From 6db5715607dd27ac64909d9e1bfcd519d56b5e92 Mon Sep 17 00:00:00 2001 From: Villu Ruusmann <villu.ruusmann@gmail.com> Date: Sun, 3 Dec 2023 22:29:07 +0200 Subject: [PATCH] Ensured compatibility with Pandas 2.1(.3) --- sklearn2pmml/util/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sklearn2pmml/util/__init__.py b/sklearn2pmml/util/__init__.py index a17b700..bb73a2c 100644 --- a/sklearn2pmml/util/__init__.py +++ b/sklearn2pmml/util/__init__.py @@ -7,6 +7,15 @@ import sys import types +try: + # Pandas 2.X + iso8601_format = "ISO8601" + + pandas.to_datetime("2023-12-03", format = iso8601_format) +except ValueError: + # Pandas 1.X + iso8601_format = "%Y-%m-%dT%H:%M:%S.%f" + def cast(X, dtype): if isinstance(dtype, str) and dtype.startswith("datetime64"): func = lambda x: to_pydatetime(x, dtype) @@ -57,7 +66,7 @@ def dt_transform(X, func): return Xt def to_pydatetime(X, dtype): - Xt = pandas.to_datetime(X, yearfirst = True, origin = "unix") + Xt = pandas.to_datetime(X, yearfirst = True, format = iso8601_format, origin = "unix") if hasattr(Xt, "dt"): Xt = Xt.dt if dtype == "datetime64[D]":