-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
groupby with daily frequency fails with NonExistentTimeError on clock change day in Brazil #23742
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
Comments
I get the same error as you in the latest release v0.23.4, but this does not raise on master (as lot of timezone things were fixed recently) and will be available with the upcomming v0.24.0 release.
Canonically though, |
@mroeschke : Add a test to close this? Or is this sufficiently covered? |
I think this test covers a similar pandas/pandas/tests/test_resample.py Line 2510 in db2066b
|
Hmm...might as well add a test specifically for this case then. Doesn't hurt 🙂 |
Sorry for the late reply, I only just had a look at the behavior for 0.24.0 -- indeed it does not raise anymore but I am not sure the new behavior is correct. It looks like if I call
In other words all the days get 'shifted' by the clock change, and timestamps on or after the 16th of October no longer represent the start of the local day. I guess this is correct if we consider that Note that pandas 0.23 does have the behavior I expect for New York timezone, for instance:
In the example above, Is the new behavior a conscious change or did this go unnoticed? |
In current master, the |
Hi Matthew, thanks for your reply above, this makes things clearer. I tried using
I suspect the original problem was not fixed in 0.24 but only hidden by the 'Day' vs 'Calendar Day' behavior change. I think issue will reappear when reverting this behavior change unless it is addressed in PR #22867 What's the best way to track this? Should we re-open this issue? |
Thanks for the example. A
The |
Code Sample
Problem description
This code raises
NonExistentTimeError
The root cause of the problem seems to be that pandas assumes that all days start at midnight local time, which is not the case in Sao Paulo on short clock-change days (the local canonical time goes from 23:59 on Oct 14 to 01:00 on Oct 15). The grouper tries to build a tz-aware object for 2017-10-15 00:00 which is not a valid "canonical" local time in Sao Paulo. This results in an exception being raised.
This is of course a problem when I want to aggregate daily values based on 'Sao Paulo days'.
A possible workaround is to write a custom grouper that will build the first timestamp of the day by using helper functions such as
pytz.normalize
ordateutil.tz.resolve_imaginary
.However using a custom python function for grouping significantly degrades grouping performance.
Expected Output
This should not raise an exception, it should return valid pandas group by objects. On the clock-change day, all timestamps from 2017-10-15 01:00 to 2017-10-15 23:59 local time should be grouped together and the timestamp associated with that group should be a tz-aware object representing 2017-10-15 01:00 local time.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-17134-Microsoft
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.22.0
pytest: None
pip: None
setuptools: 39.0.1
Cython: None
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 5.5.0
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: