|
7 | 7 | import pytest |
8 | 8 |
|
9 | 9 | 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 |
11 | 11 | from azure.kusto.data.response import KustoResponseDataSetV2 |
12 | 12 | import pandas |
13 | 13 | import numpy |
@@ -128,3 +128,31 @@ def test_pandas_mixed_date(): |
128 | 128 |
|
129 | 129 | assert df["Date"][0] == pandas.Timestamp(year=2023, month=12, day=12, hour=1, minute=59, second=59, microsecond=352000, tzinfo=datetime.timezone.utc) |
130 | 130 | 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