@@ -463,7 +463,7 @@ def test_non_str_names_w_duplicates():
463463 ),
464464 ],
465465)
466- def test_pandas_nullable_w_missing_values (
466+ def test_pandas_nullable_with_missing_values (
467467 data : list , dtype : str , expected_dtype : str
468468) -> None :
469469 # https://github.com/pandas-dev/pandas/issues/57643
@@ -481,6 +481,68 @@ def test_pandas_nullable_w_missing_values(
481481 assert result [2 ].as_py () is None
482482
483483
484+ @pytest .mark .parametrize (
485+ ("data" , "dtype" , "expected_dtype" ),
486+ [
487+ ([1 , 2 , 3 ], "Int64" , "int64" ),
488+ ([1 , 2 , 3 ], "Int64[pyarrow]" , "int64" ),
489+ ([1 , 2 , 3 ], "Int8" , "int8" ),
490+ ([1 , 2 , 3 ], "Int8[pyarrow]" , "int8" ),
491+ (
492+ [1 , 2 , 3 ],
493+ "UInt64" ,
494+ "uint64" ,
495+ ),
496+ (
497+ [1 , 2 , 3 ],
498+ "UInt64[pyarrow]" ,
499+ "uint64" ,
500+ ),
501+ ([1.0 , 2.25 , 5.0 ], "Float32" , "float32" ),
502+ ([1.0 , 2.25 , 5.0 ], "Float32[pyarrow]" , "float32" ),
503+ ([True , False , False ], "boolean" , "bool" ),
504+ ([True , False , False ], "boolean[pyarrow]" , "bool" ),
505+ (["much ado" , "about" , "nothing" ], "string[pyarrow_numpy]" , "large_string" ),
506+ (["much ado" , "about" , "nothing" ], "string[pyarrow]" , "large_string" ),
507+ (
508+ [datetime (2020 , 1 , 1 ), datetime (2020 , 1 , 2 ), datetime (2020 , 1 , 3 )],
509+ "timestamp[ns][pyarrow]" ,
510+ "timestamp[ns]" ,
511+ ),
512+ (
513+ [datetime (2020 , 1 , 1 ), datetime (2020 , 1 , 2 ), datetime (2020 , 1 , 3 )],
514+ "timestamp[us][pyarrow]" ,
515+ "timestamp[us]" ,
516+ ),
517+ (
518+ [
519+ datetime (2020 , 1 , 1 , tzinfo = timezone .utc ),
520+ datetime (2020 , 1 , 2 , tzinfo = timezone .utc ),
521+ datetime (2020 , 1 , 3 , tzinfo = timezone .utc ),
522+ ],
523+ "timestamp[us, Asia/Kathmandu][pyarrow]" ,
524+ "timestamp[us, tz=Asia/Kathmandu]" ,
525+ ),
526+ ],
527+ )
528+ def test_pandas_nullable_without_missing_values (
529+ data : list , dtype : str , expected_dtype : str
530+ ) -> None :
531+ # https://github.com/pandas-dev/pandas/issues/57643
532+ pa = pytest .importorskip ("pyarrow" , "11.0.0" )
533+ import pyarrow .interchange as pai
534+
535+ if expected_dtype == "timestamp[us, tz=Asia/Kathmandu]" :
536+ expected_dtype = pa .timestamp ("us" , "Asia/Kathmandu" )
537+
538+ df = pd .DataFrame ({"a" : data }, dtype = dtype )
539+ result = pai .from_dataframe (df .__dataframe__ ())["a" ]
540+ assert result .type == expected_dtype
541+ assert result [0 ].as_py () == data [0 ]
542+ assert result [1 ].as_py () == data [1 ]
543+ assert result [2 ].as_py () == data [2 ]
544+
545+
484546def test_empty_dataframe ():
485547 # https://github.com/pandas-dev/pandas/issues/56700
486548 df = pd .DataFrame ({"a" : []}, dtype = "int8" )
0 commit comments