Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Error "no attribute 'total_seconds'" with tzlocal >= 3.0 #43516

Closed
2 of 3 tasks
lgautier opened this issue Sep 11, 2021 · 3 comments · Fixed by #46425
Closed
2 of 3 tasks

BUG: Error "no attribute 'total_seconds'" with tzlocal >= 3.0 #43516

lgautier opened this issue Sep 11, 2021 · 3 comments · Fixed by #46425
Labels
Bug Compat pandas objects compatability with Numpy or Python functions Output-Formatting __repr__ of pandas objects, to_string Timezones Timezone data dtype

Comments

@lgautier
Copy link
Contributor

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import backports.zoneinfo
import datetime
import pandas

res = pandas.to_datetime(
    (datetime.datetime(
        1960, 5, 2, 0, 0,
        tzinfo=backports.zoneinfo.ZoneInfo(key='America/New_York')),
    ),
    errors='coerce')

repr(res)

Issue Description

pandas.to_datetime allows the creation of objects with a broken method __repr__(). The code example above triggers

AttributeError: 'NoneType' object has no attribute 'total_seconds'

The issue was discovered when investigating this: rpy2/rpy2#823 (comment)

Expected Behavior

Completion of repr() and a string return instead of an exception raised.

Installed Versions

INSTALLED VERSIONS

commit : 5f648bf
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-27-generic
Version : #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.2
numpy : 1.19.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 44.0.0
Cython : 0.29.21
pytest : 6.2.4
hypothesis : None
sphinx : 4.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.26.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@lgautier lgautier added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 11, 2021
@mzeitlin11
Copy link
Member

Thanks for reporting this @lgautier! Would you mind updating the title of the issue? related #37654

@mzeitlin11 mzeitlin11 added Output-Formatting __repr__ of pandas objects, to_string Timezones Timezone data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 11, 2021
@mzeitlin11 mzeitlin11 added this to the Contributions Welcome milestone Sep 11, 2021
@lgautier lgautier changed the title BUG: BUG: AttributeError: 'NoneType' object has no attribute 'total_seconds' with tzlocal >= 3.0 Sep 11, 2021
@lgautier lgautier changed the title BUG: AttributeError: 'NoneType' object has no attribute 'total_seconds' with tzlocal >= 3.0 BUG: AttributeError: 'NoneType' object has no attribute 'total_seconds' with tzlocal >= 3.0 Sep 11, 2021
@lgautier lgautier changed the title BUG: AttributeError: 'NoneType' object has no attribute 'total_seconds' with tzlocal >= 3.0 BUG: Error "no attribute 'total_seconds'" with tzlocal >= 3.0 Sep 11, 2021
@lgautier
Copy link
Contributor Author

Thanks for reporting this @lgautier! Would you mind updating the title of the issue? related #37654

Oops. Done. I added that this seems to be with tzlocal >= 3.0.

@dbivolaru
Copy link

For posterity in case other people stumble on this from a search engine:

The repercussions of this bug appear in all kind of strange places like when using merge() or brackets for DataFrames that have DateTimeIndex'es or MultiIndexes containing non-naive timestamps, and, it's very hard to pin down or troubleshoot.

One work-around for now is to specify in your requirements.txt a lower version of tzlocal==2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions Output-Formatting __repr__ of pandas objects, to_string Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants