Add support for datetime with zoneinfo tzinfo #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
.