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

Handling of timezone-aware pandas dataframes/series #33

Open
pyRobShrk opened this issue Apr 30, 2024 · 0 comments
Open

Handling of timezone-aware pandas dataframes/series #33

pyRobShrk opened this issue Apr 30, 2024 · 0 comments

Comments

@pyRobShrk
Copy link

  • pyhecdss version: 1.1.4 and 1.4
  • Python version: 3.7.7 and 3.11.8
  • Operating System: Windows

Description

Trying to download USGS data using dataretrieval, and subsequently write it to DSS.

What I Tried

from dataretrieval import nwis
import pyhecdss
df, meta = nwis.get_iv('11455495', '2021-06-01', parameterCd='00095')
ts = df['00095_lower-4 ft from bed'].tz_convert('America/Los_Angeles').tz_localize(None)
with pyhecdss.DSSFile('usgs.dss', create_new=True) as f:
    f.write_its('/A/B/EC//IR-MONTH/USGS/', ts, 'mmhos','INST-VAL')

Notes

The above code fails silently - no error just a blank dss file. The silent error is caused by trying to write more than one value with the same timestamp (tz_convert includes daylight savings). If you try to write the data in UTC, pandas throws an error from line 710 of pyhecdss.py: TypeError: Timestamp subtraction must have the same timezones or no timezones.

End-user fix

df.set_index(df.index.tz_localize(None) - pd.Timedelta('8h'), inplace=True)

Possible Improvements

  • In write_its, an error should be thrown for duplicate timestamps. Check that len(df.index) == len(df.index.unique()) before trying to write to dss.
  • Add support for writing timezone-aware pandas data to DSS with timezone attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant