@@ -334,31 +334,32 @@ def get_df_dtype_backend(dtype_backend: Literal["numpy_nullable", "pyarrow"] = "
334
334
"int32_nullable" : [1 , None , 3 ],
335
335
"int64_nullable" : [1 , None , 3 ],
336
336
"float_nullable" : [0.0 , None , 2.2 ],
337
- # "bool_nullable": [True, None, False],
337
+ "bool_nullable" : [True , None , False ],
338
338
"string_nullable" : ["Washington" , None , "Seattle" ],
339
- # "date_nullable": [dt("2020-01-01"), None, dt("2020-01-02")],
340
- # "timestamp_nullable": [ts("2020-01-01 00:00:00.0"), None, ts("2020-01-02 00:00:01.0")],
339
+ "date_nullable" : [dt ("2020-01-01" ), None , dt ("2020-01-02" )],
340
+ "timestamp_nullable" : [ts ("2020-01-01 00:00:00.0" ), None , ts ("2020-01-02 00:00:01.0" )],
341
341
}
342
342
)
343
343
if dtype_backend == "numpy_nullable" :
344
- df ["int8_nullable" ] = df ["int8_nullable" ].astype ("Int8" )
345
- df ["int16_nullable" ] = df ["int16_nullable" ].astype ("Int16" )
346
- df ["int32_nullable" ] = df ["int32_nullable" ].astype ("Int32" )
347
- df ["int64_nullable" ] = df ["int64_nullable" ].astype ("Int64" )
348
- df ["float_nullable" ] = df ["float_nullable" ].astype ("Float64" )
349
- # df["bool_nullable"] = df["bool_nullable"].astype("boolean")
350
- # df["date_nullable"] = df["date_nullable"].astype("string[python]")
351
- df ["string_nullable" ] = df ["string_nullable" ].astype ("string[python]" )
344
+ df ["int8_nullable" ] = df ["int8_nullable" ].astype (pd .Int8Dtype ())
345
+ df ["int16_nullable" ] = df ["int16_nullable" ].astype (pd .Int16Dtype ())
346
+ df ["int32_nullable" ] = df ["int32_nullable" ].astype (pd .Int32Dtype ())
347
+ df ["int64_nullable" ] = df ["int64_nullable" ].astype (pd .Int64Dtype ())
348
+ df ["float_nullable" ] = df ["float_nullable" ].astype (pd .Float64Dtype ())
349
+ df ["bool_nullable" ] = df ["bool_nullable" ].astype (pd .BooleanDtype ())
350
+ df ["string_nullable" ] = df ["string_nullable" ].astype (pd .StringDtype ())
351
+ df ["timestamp_nullable" ] = df ["timestamp_nullable" ].astype (pd .DatetimeTZDtype ())
352
+ df ["date_nullable" ] = df ["date_nullable" ].astype (pd .StringDtype ())
352
353
elif dtype_backend == "pyarrow" :
353
354
df ["int8_nullable" ] = df ["int8_nullable" ].astype (pd .ArrowDtype (pa .int8 ()))
354
355
df ["int16_nullable" ] = df ["int16_nullable" ].astype (pd .ArrowDtype (pa .int16 ()))
355
356
df ["int32_nullable" ] = df ["int32_nullable" ].astype (pd .ArrowDtype (pa .int32 ()))
356
357
df ["int64_nullable" ] = df ["int64_nullable" ].astype (pd .ArrowDtype (pa .int64 ()))
357
358
df ["float_nullable" ] = df ["float_nullable" ].astype (pd .ArrowDtype (pa .float64 ()))
358
- # df["bool_nullable"] = df["bool_nullable"].astype(pd.ArrowDtype(pa.bool_()))
359
- # df["date_nullable"] = df["date_nullable"].astype(pd.ArrowDtype(pa.string()))
359
+ df ["bool_nullable" ] = df ["bool_nullable" ].astype (pd .ArrowDtype (pa .bool_ ()))
360
360
df ["string_nullable" ] = df ["string_nullable" ].astype (pd .ArrowDtype (pa .string ()))
361
- # df["timestamp_nullable"] = df["timestamp_nullable"].astype("date64[ms][pyarrow]")
361
+ df ["date_nullable" ] = df ["date_nullable" ].astype (pd .ArrowDtype (pa .date32 ()))
362
+ df ["timestamp_nullable" ] = df ["timestamp_nullable" ].astype (pd .ArrowDtype (pa .timestamp ("ns" )))
362
363
else :
363
364
raise ValueError (f"Unknown dtype_backend: { dtype_backend } " )
364
365
return df
0 commit comments