Add nanosecond attribute to DateTime for compatibility with pandas
See original GitHub issueConstructing a DataFrame
from pendulum DateTime
fails because of missing nanosecond
attribute:
import pandas
import pendulum
pandas.DataFrame({'time': [pendulum.now()]})
...
File "pandas/_libs/tslibs/conversion.pyx", line 178, in pandas._libs.tslibs.conversion.datetime_to_datetime64
File "pandas/_libs/tslibs/conversion.pyx", line 387, in pandas._libs.tslibs.conversion.convert_datetime_to_tsobject
AttributeError: 'DateTime' object has no attribute 'nanosecond'
However suing naive()
it works:
pandas.DataFrame({'time': [pendulum.now().naive()]})
Out[5]:
time
0 2018-06-29T13:30:30.540966
Would it be possible to add the nanosecond
attribute to DateTime
class, event if it always returns 0 for now?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
pandas out of bounds nanosecond timestamp after offset ...
Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to ...
Read more >pandas.Timestamp — pandas 1.5.2 documentation
Pandas replacement for python datetime.datetime object. Timestamp is the pandas equivalent of python's Datetime and is interchangeable with it in most cases.
Read more >Time series / date functionality — pandas 1.5.2 documentation
Date times: A specific date and time with timezone support. Similar to datetime.datetime from the standard library. Time deltas: An absolute time duration....
Read more >pandas.Timestamp — pandas 0.25.0 documentation
Pandas replacement for python datetime.datetime object. Timestamp is the pandas equivalent of python's Datetime and is interchangeable with it in most cases.
Read more >Time series / date functionality - Pandas
pandas supports converting integer or float epoch times to Timestamp and DatetimeIndex . The default unit is nanoseconds, since that is how Timestamp...
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
Issue Example
Console Output
It appears as though pandas converts the datetime to a datetime64 behind the scenes, and validation of the datetime is throwing an exception.
Solution
You can manually reformat the date without the nanonseconds so that it passes pandas validation:
Usage
Console Output
Alternatively with a list comprehension
Console Output
This said, It would just be nice to have both tools work happily together. @jwkvam @Dmitrii-I