Skip to content

Commit cfdfe37

Browse files
authored
Don't use infer_datetime_format for pandas (#79)
* Don't use infer_datetime_format for pandas * update changelog
1 parent 2de5bca commit cfdfe37

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,4 @@ v0.2.6:
106106
2023-05-24 -- Use token for PyPi in Makefile
107107
v0.2.7b1:
108108
2025-03-01 -- https://github.com/hapi-server/client-python/issues/76
109+
2025-03-01 -- https://github.com/hapi-server/client-python/issues/78

hapiclient/hapitime.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def hapitime2datetime(Time, **kwargs):
272272

273273
try:
274274
# This is the fastest conversion option. But it will fail on YYYY-DOY
275-
# format and other valid ISO 8601 dates such as 2001-01-01T00:00:03.Z
275+
# format and other valid^* ISO 8601 dates such as 2001-01-01T00:00:03.Z
276+
# ^*Maybe not: https://github.com/hapi-server/client-python/issues/76
276277
# When infer_datetime_format is used, a TimeStamp object returned,
277278
# which is the reason for the to_pydatetime() call. (When format=... is
278279
# used, a datetime object is returned.)
@@ -281,7 +282,11 @@ def hapitime2datetime(Time, **kwargs):
281282
# is the reason for the call to tz_convert(tzinfo).
282283
# TODO: Use hapitime_format_str() and pass this as format=...
283284
Timeo = Time[0]
284-
Time = pandas.to_datetime(Time, infer_datetime_format=True).tz_convert(tzinfo).to_pydatetime()
285+
pandas_major_version = int(pandas.__version__.split('.')[0])
286+
if pandas_major_version < 2:
287+
Time = pandas.to_datetime(Time, infer_datetime_format=True).tz_convert(tzinfo).to_pydatetime()
288+
else:
289+
Time = pandas.to_datetime(Time).tz_convert(tzinfo).to_pydatetime()
285290
if reshape:
286291
Time = np.reshape(Time, shape)
287292
toc = time.time() - tic

0 commit comments

Comments
 (0)