Skip to content

BUG: Month Start Grouper raises NonExistentTimeError in some timezones #55593

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

Closed
2 of 3 tasks
mick88 opened this issue Oct 19, 2023 · 2 comments
Closed
2 of 3 tasks

BUG: Month Start Grouper raises NonExistentTimeError in some timezones #55593

mick88 opened this issue Oct 19, 2023 · 2 comments
Assignees
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@mick88
Copy link

mick88 commented Oct 19, 2023

Pandas version checks

  • 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 main branch of pandas.

Reproducible Example

import pandas as pd
idx = pd.date_range(start='2017-09-10', end='2017-11-01', freq='1D')
idx = idx.tz_localize('UTC').tz_convert('America/Asuncion')
df = pd.DataFrame(data=list(range(len(idx))), index=idx)
grouper = pd.Grouper(freq='MS')
groups = df.groupby(grouper)

Issue Description

Month Start Grouper raises NonExistentTimeError in some timezones where DST starts on first dat of the month at midnight.

For example in America/Asuncion DST starts on 1st October at midnight.
Running the above example raises the following error:

pytz.exceptions.NonExistentTimeError: 2017-10-01 00:00:00

Available workarounds:
Convert dates to UTC and operate on UTC timezone - this will prevent the error, but will cause dates to be bucketed in the wrong month if datetimes are close to the month start/end. The further the tz is from UTC, the more noticeable the problem.

Expected Behavior

I would expect Month Start to use a valid date, like 2017-10-01 01:00:00 as the start of the month.
nonexistent='shift_forward' argument to Grouper would be appreciated to control this behaviour.

Installed Versions

INSTALLED VERSIONS

commit : e86ed37
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 186 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Ireland.1252

pandas : 2.1.1
numpy : 1.22.4
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : 6.2.1
blosc : None
feather : None
xlsxwriter : 3.1.2
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
bs4 : 4.11.1
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@mick88 mick88 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 19, 2023
@gupta-paras
Copy link
Contributor

take

@mroeschke
Copy link
Member

Thanks for the report. I think this is the same core issue as #51211 so closing in favor of that one #51211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants