ENH: Series Creation Does Not Intelligently Handle datetime.date
See original GitHub issueFor 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]')
Issue Analytics
- State:
- Created 10 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Trying to mock datetime.date.today(), but not working
This fails because Python built-in types are immutable - see this answer for more details. In this case, I would subclass datetime.date myself...
Read more >Using Python datetime to Work With Dates and Times
Have you ever wondered about working with dates and times in Python? In this tutorial, you'll learn all about the built-in Python datetime...
Read more >Datetime formats - Automation Anywhere Documentation
Specify a custom format when you convert a datetime value to a string value by using the predefined formats available in RPA Workspace....
Read more >How to Use Python's datetime - KDnuggets
Python's datetime package is a convenient set of tools for working with dates and times. With just the five tricks that I'm about...
Read more >Dealing with DateTime Features in Python and Pandas
In this article, we will first have a look at how to handle date and time features with Python's DateTime module and then...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
.@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.