diff --git a/tests/test_api_types.py b/tests/test_api_types.py index 30ac31f4d..1cd77a6f1 100644 --- a/tests/test_api_types.py +++ b/tests/test_api_types.py @@ -362,15 +362,20 @@ def test_is_object_dtype() -> None: def test_is_period_dtype() -> None: - check(assert_type(api.is_period_dtype(arr), bool), bool) - check(assert_type(api.is_period_dtype(nparr), bool), bool) - check(assert_type(api.is_period_dtype(dtylike), bool), bool) - check( - assert_type(api.is_period_dtype(dframe), bool), - bool, - ) - check(assert_type(api.is_period_dtype(ind), bool), bool) - check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool) + with pytest_warns_bounded( + FutureWarning, + match="is_period_dtype is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(api.is_period_dtype(arr), bool), bool) + check(assert_type(api.is_period_dtype(nparr), bool), bool) + check(assert_type(api.is_period_dtype(dtylike), bool), bool) + check( + assert_type(api.is_period_dtype(dframe), bool), + bool, + ) + check(assert_type(api.is_period_dtype(ind), bool), bool) + check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool) def test_is_re() -> None: @@ -416,9 +421,14 @@ def test_is_signed_integer_dtype() -> None: def test_is_sparse() -> None: - check(assert_type(api.is_sparse(arr), bool), bool) - check(assert_type(api.is_sparse(nparr), bool), bool) - check(assert_type(api.is_sparse(dframe), bool), bool) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(api.is_sparse(arr), bool), bool) + check(assert_type(api.is_sparse(nparr), bool), bool) + check(assert_type(api.is_sparse(dframe), bool), bool) def test_is_string_dtype() -> None: diff --git a/tests/test_frame.py b/tests/test_frame.py index eb34fddbd..517d737cc 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1098,17 +1098,22 @@ def test_to_markdown() -> None: def test_types_to_feather() -> None: pytest.importorskip("pyarrow") df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]}) - with ensure_clean() as path: - df.to_feather(path) - # kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html - df.to_feather(path, compression="zstd", compression_level=3, chunksize=2) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + with ensure_clean() as path: + df.to_feather(path) + # kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html + df.to_feather(path, compression="zstd", compression_level=3, chunksize=2) - # to_feather has been able to accept a buffer since pandas 1.0.0 - # See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html - # Docstring and type were updated in 1.2.0. - # https://github.com/pandas-dev/pandas/pull/35408 - with open(path, mode="wb") as file: - df.to_feather(file) + # to_feather has been able to accept a buffer since pandas 1.0.0 + # See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html + # Docstring and type were updated in 1.2.0. + # https://github.com/pandas-dev/pandas/pull/35408 + with open(path, mode="wb") as file: + df.to_feather(file) # compare() method added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html @@ -1339,9 +1344,14 @@ def test_types_to_parquet() -> None: allows_duplicate_labels=False ) with ensure_clean() as path: - df.to_parquet(Path(path)) - # to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html - b: bytes = df.to_parquet() + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + df.to_parquet(Path(path)) + # to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html + b: bytes = df.to_parquet() def test_types_to_latex() -> None: diff --git a/tests/test_io.py b/tests/test_io.py index f9cc3e841..e17e2de25 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -69,7 +69,10 @@ from pandas.io.sas.sas_xport import XportReader from pandas.io.stata import StataReader -from . import lxml_skip +from . import ( + lxml_skip, + pytest_warns_bounded, +) DF = DataFrame({"a": [1, 2, 3], "b": [0.0, 0.0, 0.0]}) CWD = os.path.split(os.path.abspath(__file__))[0] @@ -78,7 +81,12 @@ @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") def test_orc(): with ensure_clean() as path: - check(assert_type(DF.to_orc(path), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_orc(path), None), type(None)) check(assert_type(read_orc(path), DataFrame), DataFrame) @@ -86,7 +94,12 @@ def test_orc(): def test_orc_path(): with ensure_clean() as path: pathlib_path = Path(path) - check(assert_type(DF.to_orc(pathlib_path), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_orc(pathlib_path), None), type(None)) check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame) @@ -94,7 +107,12 @@ def test_orc_path(): def test_orc_buffer(): with ensure_clean() as path: file_w = open(path, "wb") - check(assert_type(DF.to_orc(file_w), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_orc(file_w), None), type(None)) file_w.close() file_r = open(path, "rb") @@ -105,13 +123,23 @@ def test_orc_buffer(): @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") def test_orc_columns(): with ensure_clean() as path: - check(assert_type(DF.to_orc(path, index=False), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_orc(path, index=False), None), type(None)) check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame) @pytest.mark.skipif(WINDOWS, reason="ORC not available on windows") def test_orc_bytes(): - check(assert_type(DF.to_orc(index=False), bytes), bytes) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_orc(index=False), bytes), bytes) @lxml_skip @@ -504,27 +532,47 @@ def test_json_chunk(): def test_parquet(): with ensure_clean() as path: - check(assert_type(DF.to_parquet(path), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_parquet(path), None), type(None)) + check(assert_type(DF.to_parquet(), bytes), bytes) check(assert_type(read_parquet(path), DataFrame), DataFrame) - check(assert_type(DF.to_parquet(), bytes), bytes) def test_parquet_options(): with ensure_clean(".parquet") as path: - check( - assert_type(DF.to_parquet(path, compression=None, index=True), None), - type(None), - ) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check( + assert_type(DF.to_parquet(path, compression=None, index=True), None), + type(None), + ) check(assert_type(read_parquet(path), DataFrame), DataFrame) def test_feather(): with ensure_clean() as path: - check(assert_type(DF.to_feather(path), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_feather(path), None), type(None)) check(assert_type(read_feather(path), DataFrame), DataFrame) check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame) bio = io.BytesIO() - check(assert_type(DF.to_feather(bio), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.00", + ): + check(assert_type(DF.to_feather(bio), None), type(None)) bio.seek(0) check(assert_type(read_feather(bio), DataFrame), DataFrame) @@ -1322,13 +1370,22 @@ def test_all_read_without_lxml_dtype_backend() -> None: con.close() if not WINDOWS: - check(assert_type(DF.to_orc(path), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_orc(path), None), type(None)) check( assert_type(read_orc(path, dtype_backend="numpy_nullable"), DataFrame), DataFrame, ) - - check(assert_type(DF.to_feather(path), None), type(None)) + with pytest_warns_bounded( + FutureWarning, + match="is_sparse is deprecated and will be removed in a future version", + lower="2.0.99", + ): + check(assert_type(DF.to_feather(path), None), type(None)) check( assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame), DataFrame,