File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -304,6 +304,18 @@ def _apply_changes(self, use_new: bool):
304304 df [col ] = df [col ].astype (dtype )
305305 elif np .issubdtype (dtype , np .number ):
306306 df [col ] = pd .to_numeric (df [col ], errors = "coerce" )
307+ # If original dtype was integer and column has NaN, use nullable Int type
308+ if np .issubdtype (dtype , np .integer ) and df [col ].isna ().any ():
309+ if dtype == np .int64 :
310+ df [col ] = df [col ].astype ("Int64" )
311+ elif dtype == np .int32 :
312+ df [col ] = df [col ].astype ("Int32" )
313+ elif dtype == np .int16 :
314+ df [col ] = df [col ].astype ("Int16" )
315+ elif dtype == np .int8 :
316+ df [col ] = df [col ].astype ("Int8" )
317+ else :
318+ df [col ] = df [col ].astype ("Int64" )
307319 else :
308320 df [col ] = df [col ].astype (dtype )
309321
You can’t perform that action at this time.
0 commit comments