Skip to content

Commit acd5627

Browse files
committed
back
1 parent d4e5aa5 commit acd5627

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

azure-kusto-data/tests/test_helpers.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88

99
from azure.kusto.data._models import KustoResultTable
10-
from azure.kusto.data.helpers import dataframe_from_result_table
10+
from azure.kusto.data.helpers import dataframe_from_result_table, parse_datetime
1111
from azure.kusto.data.response import KustoResponseDataSetV2
1212
import pandas
1313
import numpy
@@ -128,3 +128,31 @@ def test_pandas_mixed_date():
128128

129129
assert df["Date"][0] == pandas.Timestamp(year=2023, month=12, day=12, hour=1, minute=59, second=59, microsecond=352000, tzinfo=datetime.timezone.utc)
130130
assert df["Date"][1] == pandas.Timestamp(year=2023, month=12, day=12, hour=1, minute=54, second=44, tzinfo=datetime.timezone.utc)
131+
132+
133+
def test_parse_datetime():
134+
"""Test parse_datetime function with different pandas versions and datetime formats"""
135+
136+
# Test with pandas v2 behavior (force version 2)
137+
df_v2 = pandas.DataFrame(
138+
{
139+
"mixed": ["2023-12-12T01:59:59.352Z", "2023-12-12T01:54:44Z"],
140+
}
141+
)
142+
143+
# Force pandas v2 behavior
144+
result_v2 = parse_datetime(df_v2, "mixed", force_version="2.0.0")
145+
assert str(result_v2[0]) == "2023-12-12 01:59:59.352000+00:00"
146+
assert str(result_v2[1]) == "2023-12-12 01:54:44+00:00"
147+
# Test with pandas v1 behavior (force version 1)
148+
149+
df_v1 = pandas.DataFrame(
150+
{
151+
"mixed": ["2023-12-12T01:59:59.352Z", "2023-12-12T01:54:44Z"],
152+
}
153+
)
154+
155+
# Force pandas v1 behavior - it should add .000 to dates without milliseconds
156+
result_v1 = parse_datetime(df_v1, "mixed", force_version="1.5.3")
157+
assert str(result_v1[0]) == "2023-12-12 01:59:59.352000+00:00"
158+
assert str(result_v1[1]) == "2023-12-12 01:54:44+00:00"

0 commit comments

Comments
 (0)