Skip to content

Commit e13fb52

Browse files
committed
Fix the numpy version issue
1 parent d2d817d commit e13fb52

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

terminusdb_client/scripts/scripts.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import builtins
21
import datetime as dt
32
import enum
43
import json
@@ -439,7 +438,6 @@ def importcsv(
439438
embedded = [x.lower().replace(" ", "_") for x in embedded]
440439
try:
441440
pd = import_module("pandas")
442-
np = import_module("numpy")
443441
except ImportError:
444442
raise ImportError(
445443
"Library 'pandas' is required to import csv, either install 'pandas' or install woqlDataframe requirements as follows: python -m pip install -U terminus-client-python[dataframe]"
@@ -455,19 +453,27 @@ def importcsv(
455453

456454
def _df_to_schema(class_name, df):
457455
class_dict = {"@type": "Class", "@id": class_name}
458-
np_to_buildin = {
459-
v: getattr(builtins, k)
460-
for k, v in np.sctypeDict.items()
461-
if k in vars(builtins)
462-
}
463-
np_to_buildin[np.datetime64] = dt.datetime
464456
for col, dtype in dict(df.dtypes).items():
465457
if embedded and col in embedded:
466458
converted_type = class_name
467459
else:
468-
converted_type = np_to_buildin[dtype.type]
469-
if converted_type is object:
470-
converted_type = str # pandas treats all string as objects
460+
# Map pandas/numpy dtype to Python type
461+
# Uses dtype.kind for compatibility with numpy 2.0+ and pandas 3.0+
462+
dtype_kind = getattr(dtype, "kind", "O")
463+
if dtype.type is str or dtype_kind in ("U", "O", "S", "T"):
464+
converted_type = str
465+
elif dtype_kind in ("i", "u"):
466+
converted_type = int
467+
elif dtype_kind == "f":
468+
converted_type = float
469+
elif dtype_kind == "b":
470+
converted_type = bool
471+
elif dtype_kind == "M":
472+
converted_type = dt.datetime
473+
elif dtype_kind == "m":
474+
converted_type = dt.timedelta
475+
else:
476+
converted_type = str
471477
converted_type = wt.to_woql_type(converted_type)
472478

473479
if id_ and col == id_:

0 commit comments

Comments
 (0)