diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 541d021791f35..0c3d85cbcb620 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -28,13 +28,26 @@ The available extras, found in the :ref:`installation guide ArrayLike: diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index bff4c98fe2842..822e24b224052 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -536,7 +536,11 @@ def test_reader_dtype_str(self, read_ext, dtype, expected): actual = pd.read_excel(basename + read_ext, dtype=dtype) tm.assert_frame_equal(actual, expected) - def test_use_nullable_dtypes(self, read_ext): + @pytest.mark.parametrize( + "nullable_backend", + ["pandas", pytest.param("pyarrow", marks=td.skip_if_no("pyarrow"))], + ) + def test_use_nullable_dtypes(self, read_ext, nullable_backend): # GH#36712 if read_ext in (".xlsb", ".xls"): pytest.skip(f"No engine for filetype: '{read_ext}'") @@ -557,10 +561,30 @@ def test_use_nullable_dtypes(self, read_ext): ) with tm.ensure_clean(read_ext) as file_path: df.to_excel(file_path, "test", index=False) - result = pd.read_excel( - file_path, sheet_name="test", use_nullable_dtypes=True + with pd.option_context("io.nullable_backend", nullable_backend): + result = pd.read_excel( + file_path, sheet_name="test", use_nullable_dtypes=True + ) + if nullable_backend == "pyarrow": + import pyarrow as pa + + from pandas.arrays import ArrowExtensionArray + + expected = DataFrame( + { + col: ArrowExtensionArray(pa.array(df[col], from_pandas=True)) + for col in df.columns + } ) - tm.assert_frame_equal(result, df) + # pyarrow by default infers timestamp resolution as us, not ns + expected["i"] = ArrowExtensionArray( + expected["i"].array._data.cast(pa.timestamp(unit="us")) + ) + # pyarrow supports a null type, so don't have to default to Int64 + expected["j"] = ArrowExtensionArray(pa.array([None, None])) + else: + expected = df + tm.assert_frame_equal(result, expected) def test_use_nullabla_dtypes_and_dtype(self, read_ext): # GH#36712