Skip to content

Commit 3ef98e0

Browse files
committed
Add support for datetime with zoneinfo tzinfo
By converting input_datetime (string or datetime object) to a string before applying pandas' to_datetime, compatibility issues between pandas and zoneinfo are circumvented (pandas-dev/pandas#37654). + fix typos and remove duplicate code
1 parent b66a796 commit 3ef98e0

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/pywaterinfo/waterinfo.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _parse_date(input_datetime, timezone="UTC"):
344344
we normalize everything to UTC by default. Hence, we interpret the user
345345
input as UTC, provide the input to the API as CET and request the returned
346346
output data as UTC. If the user provides a timezone, we interpret user input as
347-
the given timezone, doe the request in CET and return th output data in the
347+
the given timezone, do the request in CET and return the output data in the
348348
requested timezone.
349349
350350
Parameters
@@ -359,16 +359,12 @@ def _parse_date(input_datetime, timezone="UTC"):
359359
f"{timezone} is not a valid timezone string."
360360
)
361361

362-
input_timestamp = pd.to_datetime(input_datetime)
362+
input_timestamp = pd.to_datetime(str(input_datetime))
363363

364-
if input_timestamp.tz: # timestamp already contains tz info
365-
return input_timestamp.tz_convert("CET").strftime("%Y-%m-%d %H:%M:%S")
366-
else:
367-
return (
368-
input_timestamp.tz_localize(timezone)
369-
.tz_convert("CET")
370-
.strftime("%Y-%m-%d %H:%M:%S")
371-
)
364+
if not input_timestamp.tz: # timestamp does not contain tz info
365+
input_timestamp = input_timestamp.tz_localize(timezone)
366+
367+
return input_timestamp.tz_convert("CET").strftime("%Y-%m-%d %H:%M:%S")
372368

373369
def _parse_period(self, start=None, end=None, period=None, timezone="UTC"):
374370
"""Check the from/to/period arguments when requesting

0 commit comments

Comments
 (0)