42
42
from hopsworks_common import client
43
43
from hopsworks_common .client .exceptions import FeatureStoreException , JobException
44
44
from hopsworks_common .constants import MODEL , PREDICTOR , Default
45
+ from hopsworks_common .core .constants import HAS_PANDAS
45
46
from hopsworks_common .git_file_status import GitFileStatus
46
47
from six import string_types
47
48
@@ -72,7 +73,9 @@ def convert(self, obj):
72
73
import base64
73
74
74
75
import numpy as np
75
- import pandas as pd
76
+
77
+ if HAS_PANDAS :
78
+ import pandas as pd
76
79
77
80
def encode_binary (x ):
78
81
return base64 .encodebytes (x ).decode ("ascii" )
@@ -85,7 +88,9 @@ def encode_binary(x):
85
88
else :
86
89
return obj .tolist (), True
87
90
88
- if isinstance (obj , (pd .Timestamp , datetime .date )):
91
+ if isinstance (obj , datetime .date ) or (
92
+ HAS_PANDAS and isinstance (obj , pd .Timestamp )
93
+ ):
89
94
return obj .isoformat (), True
90
95
if isinstance (obj , bytes ) or isinstance (obj , bytearray ):
91
96
return encode_binary (obj ), True
@@ -512,14 +517,16 @@ def _handle_tensor_input(input_tensor):
512
517
513
518
514
519
def _handle_dataframe_input (input_ex ):
515
- if isinstance (input_ex , pd .DataFrame ):
520
+ if HAS_PANDAS :
521
+ import pandas as pd
522
+ if HAS_PANDAS and isinstance (input_ex , pd .DataFrame ):
516
523
if not input_ex .empty :
517
524
return input_ex .iloc [0 ].tolist ()
518
525
else :
519
526
raise ValueError (
520
527
"input_example of type {} can not be empty" .format (type (input_ex ))
521
528
)
522
- elif isinstance (input_ex , pd .Series ):
529
+ elif HAS_PANDAS and isinstance (input_ex , pd .Series ):
523
530
if not input_ex .empty :
524
531
return input_ex .tolist ()
525
532
else :
0 commit comments