Skip to content

Commit

Permalink
Fix rounding of Pandas datetimes in ICON CMORizer (#2529)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <[email protected]>
  • Loading branch information
valeriupredoi and schlunma authored Sep 26, 2024
1 parent ffa2347 commit f7ab83f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
- netcdf4
- numpy !=1.24.3,<2.0.0 # avoid pulling 2.0.0rcX
- packaging
- pandas !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349
- pandas
- pillow
- pip !=21.3
- prov
Expand Down
7 changes: 5 additions & 2 deletions esmvalcore/cmor/_fixes/icon/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,11 @@ def _fix_invalid_time_units(time_coord):
# Finally, add date and day fraction to get final datetime and convert
# it to correct units. Note: we also round to next second, otherwise
# this results in times that are off by 1s (e.g., 13:59:59 instead of
# 14:00:00).
rounded_datetimes = (year_month_day + day_float).round('s')
# 14:00:00). We round elements individually since rounding the
# pd.Series object directly is broken
# (https://github.com/pandas-dev/pandas/issues/57002).
datetimes = year_month_day + day_float
rounded_datetimes = pd.Series(dt.round('s') for dt in datetimes)
with warnings.catch_warnings():
# We already fixed the deprecated code as recommended in the
# warning, but it still shows up -> ignore it
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'netCDF4',
'numpy!=1.24.3,<2.0.0', # avoid pulling 2.0.0rc1
'packaging',
'pandas!=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc
'pandas',
'pillow',
'prov',
'psutil',
Expand Down

0 comments on commit f7ab83f

Please sign in to comment.