Skip to content

Commit cbee189

Browse files
committed
Import changes from other branch
1 parent 3ed2cb1 commit cbee189

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Changed extra's name back to `aio`
12+
- Fixed handling of datetime columns in old pandas versions. (#609)
1213

1314
## [6.0.0] - 2025-11-26
1415

azure-kusto-data/azure/kusto/data/helpers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import json
22
from functools import lru_cache
33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Union, Callable, Dict, Optional
4+
from typing import TYPE_CHECKING, Any, Union, Callable, Optional
55

66
if TYPE_CHECKING:
77
import pandas as pd
88
from azure.kusto.data._models import KustoResultTable, KustoStreamingResultTable
99

1010
# Alias for dataframe_from_result_table converter type
11-
Converter = Dict[str, Union[str, Callable[[str, "pd.DataFrame"], "pd.Series"]]]
11+
Converter = dict[str, Union[str, Callable[[str, "pd.DataFrame"], "pd.Series['Any']"]]]
1212

1313

14-
def load_bundled_json(file_name: str) -> Dict:
14+
def load_bundled_json(file_name: str) -> dict[Any, Any]:
1515
filename = Path(__file__).absolute().parent.joinpath(file_name)
1616
with filename.open("r", encoding="utf-8") as data:
1717
return json.load(data)
@@ -118,18 +118,18 @@ def parse_float(frame, col):
118118
return frame[col]
119119

120120

121-
def parse_datetime(frame, col):
121+
def parse_datetime(frame, col, force_version: Optional[str] = None):
122122
# Pandas before version 2 doesn't support the "format" arg
123123
import pandas as pd
124124

125125
args = {}
126-
if pd.__version__.startswith("2."):
126+
if (force_version or pd.__version__).startswith("2."):
127127
args = {"format": "ISO8601", "utc": True}
128128
else:
129129
# if frame contains ".", replace "Z" with ".000Z"
130130
# == False is not a mistake - that's the pandas way to do it
131-
contains_dot = frame[col].str.contains(".")
132-
frame.loc[not contains_dot, col] = frame.loc[not contains_dot, col].str.replace("Z", ".000Z")
131+
contains_dot = frame[col].str.contains("\\.")
132+
frame.loc[~contains_dot, col] = frame.loc[~contains_dot, col].str.replace("Z", ".000Z")
133133
frame[col] = pd.to_datetime(frame[col], errors="coerce", **args)
134134
return frame[col]
135135

0 commit comments

Comments
 (0)