@@ -73,6 +73,9 @@ def deserialize_input(self, input_data):
7373 if self .enforce_column_type :
7474 sample_input_column_types = self .sample_input .dtypes .to_dict ()
7575 converted_types = {x : sample_input_column_types .get (x , object ) for x in data_frame .columns }
76+ for column_name , column_type in converted_types .items ():
77+ if str (column_type ).startswith ('timedelta' ):
78+ data_frame [column_name ] = pd .to_timedelta (data_frame [column_name ])
7679 data_frame = data_frame .astype (dtype = converted_types )
7780
7881 if self .enforce_shape :
@@ -101,11 +104,44 @@ def input_to_swagger(self):
101104 :rtype: dict
102105 """
103106 LIST_LIKE_ORIENTS = ('records' , 'values' )
104- json_sample = json .loads (self .sample_input .to_json (orient = self .orient ))
107+ json_sample = json .loads (self .sample_input .to_json (orient = self .orient , date_format = 'iso' ))
105108
106109 if self .orient in LIST_LIKE_ORIENTS :
107110 swagger_schema = get_swagger_for_list (json_sample )
108111 else :
109112 swagger_schema = get_swagger_for_nested_dict (json_sample )
110113
114+ if self .orient == 'records' :
115+ for column_name in self .sample_input .columns :
116+ data_type = str (self .sample_input .dtypes [column_name ])
117+ if data_type .startswith ('datetime' ):
118+ swagger_schema ['items' ]['properties' ][str (column_name )]['format' ] = 'date-time'
119+ elif data_type .startswith ('timedelta' ):
120+ swagger_schema ['items' ]['properties' ][str (column_name )]['format' ] = 'timedelta'
121+ elif self .orient == 'index' :
122+ for row in swagger_schema ['properties' ].values ():
123+ for column_name in self .sample_input .columns :
124+ data_type = str (self .sample_input .dtypes [column_name ])
125+ if data_type .startswith ('datetime' ):
126+ row ['properties' ][str (column_name )]['format' ] = 'date-time'
127+ elif data_type .startswith ('timedelta' ):
128+ row ['properties' ][str (column_name )]['format' ] = 'timedelta'
129+ elif self .orient == 'columns' :
130+ for column_name in self .sample_input .columns :
131+ for row_info in swagger_schema ['properties' ][str (column_name )]['properties' ].values ():
132+ data_type = str (self .sample_input .dtypes [column_name ])
133+ if data_type .startswith ('datetime' ):
134+ row_info ['format' ] = 'date-time'
135+ elif data_type .startswith ('timedelta' ):
136+ row_info ['format' ] = 'timedelta'
137+ elif self .orient == 'table' :
138+ for column_name in self .sample_input .columns :
139+ data_type = str (self .sample_input .dtypes [column_name ])
140+ if data_type .startswith ('datetime' ):
141+ swagger_schema ['properties' ]['data' ]['items' ]['properties' ][str (column_name )]['format' ] = \
142+ 'date-time'
143+ elif data_type .startswith ('timedelta' ):
144+ swagger_schema ['properties' ]['data' ]['items' ]['properties' ][str (column_name )]['format' ] = \
145+ 'timedelta'
146+
111147 return swagger_schema
0 commit comments