Skip to content

Commit

Permalink
Ensured compatibility with Pandas 2.1(.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Dec 3, 2023
1 parent 5939f84 commit 6db5715
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sklearn2pmml/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]":
Expand Down

0 comments on commit 6db5715

Please sign in to comment.