-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
DatetimeDatetime data dtypeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancement
Description
For example:
In [77]: pd.Series([datetime.datetime(2012, 1, 1)]).dtype
Out[77]: dtype('<M8[ns]')
works as expected.
However:
In [78]: pd.Series([datetime.date(2012, 1, 1)]).dtype
Out[78]: dtype('O')
create a Series of type object rather than datetime64.
You can get the desired effect:
In [89]: pd.Series(np.array([np.datetime64(datetime.date(2012, 1, 1))])).dtype
Out[89]: dtype('<M8[D]')
Metadata
Metadata
Assignees
Labels
DatetimeDatetime data dtypeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancement
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jreback commentedon Jul 24, 2013
there is nothing wrong with
datetime.date
, but it REALLY should be passed as adatetime.datetime
. Its very hard to do this 'automatically' because there is nothing technically wrong with allowing it in (its just dtyped ==object
).OTOH maybe should just do this conversion .....
and your dtype in 89 will just not work; its not a valid dtype (well in 0.11 it causes subtle issues), in 0.12 I think this will raise (but'll I'll add this as an enhancement issue)
cancan101 commentedon Jul 24, 2013
Why do you think that it should be passed in as
datetime.datetime
rather thandatetime.date
? There is something to be said about maintaining the precision of the observation as being an entire day rather than a specific point in time.Numpy theoretically supports this notion with time units: http://docs.scipy.org/doc/numpy-dev/reference/arrays.datetime.html#datetime-units
jreback commentedon Jul 24, 2013
http://pandas.pydata.org/pandas-docs/dev/gotchas.html#timestamp-limitations
jreback commentedon Jul 24, 2013
http://pandas.pydata.org/pandas-docs/dev/timeseries.html#time-span-representation
cancan101 commentedon Nov 5, 2013
Here is perhaps a cleaner example. I do think that auto conversion COULD be performed:
jtratner commentedon Nov 5, 2013
You can put something together for 0.14 if you want
cancan101 commentedon Nov 5, 2013
Sounds good. I imagine this should not be too hard.
On Nov 4, 2013 9:38 PM, "Jeff Tratner" notifications@github.com wrote:
jtratner commentedon Nov 5, 2013
I know @jreback has had a pretty good sense of what we want to support for
dates, so I'm going to defer to him on this though.
max-sixty commentedon Oct 23, 2015
Is this still active?
@jtratner mentioned @jreback had a design in mind - is that the case?
I'm hitting this in our work - loading a set of
datetime.date
objects, and getting an object rather thandatetime
index:Replacing
date
withdatetime
:jreback commentedon Oct 23, 2015
@MaximilianR
datetime.date
could be auto-converted todatetime64[ns]
though that would be an API change.handling
datetime.date
as an actual dtype, `datetime64[D]``. is possible, though would require a fair bit of work.It is not on the priority list, though you are welcome to take a look.
TomAugspurger commentedon Oct 25, 2018
I don't think we should auto-convert
datetime.date
to datetimes. They're different things. In the future, we (or a 3rd party) may make an ExtensionArray for dates, and we would have to backtrack this change.If the user wants datetimes now, then they have
pd.to_datetime
.