Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 659a338

Browse files
committed
make tests pass: tz_localize/tz_convert
1 parent b75182a commit 659a338

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

influxdb/_dataframe_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ def _to_dataframe(self, rs, dropna=True):
208208
df = pd.DataFrame(data)
209209
df.time = pd.to_datetime(df.time)
210210
df.set_index('time', inplace=True)
211-
df.index = df.index.tz_localize('UTC')
211+
try:
212+
df.index = df.index.tz_localize('UTC')
213+
except TypeError:
214+
df.index = df.index.tz_convert('UTC')
212215
df.index.name = None
213216
result[key].append(df)
214217
for key, data in result.items():

influxdb/tests/dataframe_client_test.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,19 @@ def test_query_into_dataframe(self):
818818
pd1 = pd.DataFrame(
819819
[[23422]], columns=['value'],
820820
index=pd.to_datetime(["2009-11-10T23:00:00Z"]))
821-
pd1.index = pd1.index.tz_localize('UTC')
821+
try:
822+
pd1.index = pd1.index.tz_localize('UTC')
823+
except TypeError:
824+
pd1.index = pd1.index.tz_convert('UTC')
822825
pd2 = pd.DataFrame(
823826
[[23422], [23422], [23422]], columns=['value'],
824827
index=pd.to_datetime(["2009-11-10T23:00:00Z",
825828
"2009-11-10T23:00:00Z",
826829
"2009-11-10T23:00:00Z"]))
827-
pd2.index = pd2.index.tz_localize('UTC')
830+
try:
831+
pd2.index = pd2.index.tz_localize('UTC')
832+
except TypeError:
833+
pd2.index = pd2.index.tz_convert('UTC')
828834
expected = {
829835
('network', (('direction', ''),)): pd1,
830836
('network', (('direction', 'in'),)): pd2
@@ -871,11 +877,18 @@ def test_multiquery_into_dataframe(self):
871877
index=pd.to_datetime([
872878
"2015-01-29 21:55:43.702900257+0000",
873879
"2015-01-29 21:55:43.702900257+0000",
874-
"2015-06-11 20:46:02+0000"])).tz_localize('UTC')
880+
"2015-06-11 20:46:02+0000"]))
881+
try:
882+
pd1 = pd1.tz_localize('UTC')
883+
except TypeError:
884+
pd1 = pd1.tz_convert('UTC')
875885
pd2 = pd.DataFrame(
876886
[[3]], columns=['count'],
877-
index=pd.to_datetime(["1970-01-01 00:00:00+00:00"]))\
878-
.tz_localize('UTC')
887+
index=pd.to_datetime(["1970-01-01 00:00:00+00:00"]))
888+
try:
889+
pd2 = pd2.tz_localize('UTC')
890+
except TypeError:
891+
pd2 = pd2.tz_convert('UTC')
879892
expected = [{'cpu_load_short': pd1}, {'cpu_load_short': pd2}]
880893

881894
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')

0 commit comments

Comments
 (0)