Closed dbkhout closed 2 years ago
@dbkhout thanks a lot for the very clear issue/pr!
I would like to include the fix. However, I noticed that the PR is originating from your own master
branch, which would make your fork not in sync with the master of this repo (also, I could not further extend your branch to add a unit test).
See https://github.com/fluves/pywaterinfo/pull/47 for a new PR with your additions and the unit test. However, as this would not effectively make you a contributor (registered on git/github), I propose we can do either:
closing this one, see https://github.com/fluves/pywaterinfo/pull/48
Description
pandas
is currently not compatible with thezoneinfo
module of the Python standard library (new in version 3.9). This affectspywaterinfo
through the use ofpandas.to_datetime
method inwaterinfo._parse_dates
.Example Error
Note that a
pandas.DataFrame
is still returned todf
, although it contains unexpected results for this case. This is due topandas.to_datetime
returning a correctly offset (for UTC wall time), but naive timestamp (i.e.2021-12-31 23:00:00
) instead of the expected aware timestamp (i.e.2022-01-01 00:00:00+01:00
). Because of the implementation ofwaterinfo._parse_dates
, this naive timestamp is then localized to the provided time zone, resulting in an incorrect timestamp (i.e.2021-12-31 23:00:00+01:00
).Proposed Solution
By converting
input_datetime
(string ordatetime.datetime
object) to a string before applyingpandas.to_datetime
, compatibility issues betweenpandas
andzoneinfo
are circumvented by relying on the correct implementation ofdatetime.__str__()
.Other
Corrected typos and duplicate code for
waterinfo._parse_date
.