question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Series Creation Does Not Intelligently Handle datetime.date

See original GitHub issue

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]')

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
TomAugspurgercommented, 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.

0reactions
jrebackcommented, Oct 23, 2015

@maximilianr

datetime.date could be auto-converted to datetime64[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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found