[Numpy-discussion] The date/time dtype and the casting issue
Francesc Alted
faltet at pytables.org
Wed Jul 30 13:16:25 EDT 2008
A Wednesday 30 July 2008, Pierre GM escrigué:
> > > Now, what format do you consider for this reference ?
> >
> > Whatever that can be converted into a datetime64 scalar. Some
> > examples:
> >
> > ref = '2001-04-01'
> > ref = datetime.datetime(2001, 4, 1)
>
> Er, should I see ref as having a 'day' unit or 'business day' unit in
> that case? I know that 'business days' spoil the game, but Matt
> really needs them, so...
OK. I was wrong. Of course you need to specify the resolution, so the
reference *should* be a NumPy scalar:
ref = numpy.datetime64('2001-04-01', unit="B") # 'B'usiness days
>
> > > Moreover, could you give some more examples of interaction
> > > between datetime and timedelta ?
> >
> > In the second proposal there are some examples of this interaction
> > and I'm populating the third proposal with more examples yet. Just
> > wait a bit (maybe a couple of hours) to see the new proposal.
>
> OK, with pleasure. It's just that I have trouble understanding the
> meaning of something like
> t2 = numpy.ones(5, dtype="datetime64[s]")
>
> That's five times one second after the epoch, right ? But in what
> circumstances would you need t2 ?
I'm not sure I follow you. This is just an example so as to produce an
array of time objects quickly. In general, you should also be able to
produce the same result by doing:
t2 = numpy.array(['1970-01-01T00:00:05', '1970-01-01T00:00:05',
'1970-01-01T00:00:05', '1970-01-01T00:00:05',
'1970-01-01T00:00:05', dtype="datetime64[s]")
which is more visual, but has the drawback that it's just too long for
documenting purposes. When you don't need the values for some
examples, conciseness is a virtue.
--
Francesc Alted
More information about the NumPy-Discussion
mailing list