ENH: support pendulum objects
See original GitHub issueimport pendulum
import pandas
pandas.date_range(start=pendulum.now(), end=pendulum.tomorrow())
[1] 56829 segmentation fault ipython
Problem description
As pendulum
claims to inherit from datetime.datetime
, I wouldn’t expect a segfaut to happen, as date_range
always worked find with datetime
objects
From the documentation:
The Pendulum class is a drop-in replacement for the native datetime class (it is inherited from it).
I could file an issue on the pendulum bug tracker as well, but that’s pandas who’s segfaulting, so I think you guys would have better tools to understand what’s going on.
Expected Output
DatetimeIndex(['2017-04-12 20:54:52.305104', '2017-04-13 20:54:52.305104'], dtype='datetime64[ns]', freq='D')
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None python: 3.5.2.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: fr_BE.UTF-8 LOCALE: fr_BE.UTF-8
pandas: 0.19.2 nose: None pip: 9.0.1 setuptools: 34.4.1 Cython: None numpy: 1.12.1 scipy: None statsmodels: None xarray: None IPython: 5.3.0 sphinx: None patsy: None dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: None matplotlib: None openpyxl: None xlrd: 1.0.0 xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None httplib2: None apiclient: None sqlalchemy: 1.1.9 pymysql: None psycopg2: 2.6.2 (dt dec pq3 ext lo64) jinja2: 2.9.6 boto: None pandas_datareader: None
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:10 (6 by maintainers)
Top GitHub Comments
@jreback Author of
pendulum
here 😃 What do you mean by it does not use standard timezone?So, as you can see,
pendulum
uses a subclass of the standardtzinfo
.The underlying problem comes from
pandas
since it calls:in the _get_dst_info() function.
However
total_seconds()
assumes atimedelta
while theutcoffset()
method of atzinfo
can also returnNone
.Here is what the offical Python documentation says (https://docs.python.org/3.6/library/datetime.html#datetime.tzinfo.utcoffset):
And in this case
None
is being passed toutcoffset()
so there is no way to determine the offset that’s why pendulum returnsNone
.So
None
is a valid return value, howeverpandas
will segfault when it occurs.I see that the Pendulum issue has been closed without a fix, so if anyone wants a workaround to this:
I did a roundtrip from Pendulum > ISO format > Pandas to avoid the internal lookup that causes the warning.
converted_date = pandas.to_datetime(pendulum.today().isoformat())
Not pretty but it will clean your error logs without hurting comprehension.