From 2073643f40053b0a8f11b3c0dc7e9b89b324fa59 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:54:41 -0700 Subject: [PATCH 1/3] TST: Address/catch more test warnings --- pandas/io/date_converters.py | 4 +--- pandas/tests/frame/methods/test_fillna.py | 2 +- pandas/tests/indexes/test_common.py | 3 +-- pandas/tests/io/parser/conftest.py | 7 ++++++- pandas/tests/plotting/frame/test_frame.py | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pandas/io/date_converters.py b/pandas/io/date_converters.py index 5885a3b9d14d7..99a838c61b996 100644 --- a/pandas/io/date_converters.py +++ b/pandas/io/date_converters.py @@ -92,9 +92,7 @@ def generic_parser(parse_func, *cols) -> np.ndarray: """ warnings.warn( - """ - Use pd.to_datetime instead. -""", + "Use pd.to_datetime instead.", FutureWarning, stacklevel=find_stack_level(inspect.currentframe()), ) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 4cf6706707569..3d7e5c6823e9d 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -777,6 +777,6 @@ def test_fillna_nonconsolidated_frame(): ], columns=["i1", "i2", "i3", "f1"], ) - df_nonconsol = df.pivot("i1", "i2") + df_nonconsol = df.pivot(index="i1", columns="i2") result = df_nonconsol.fillna(0) assert result.isna().sum().sum() == 0 diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index c81b3a533170e..b8591ab3a1532 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -468,8 +468,7 @@ def test_hasnans_isnans(self, index_flat): def test_sort_values_invalid_na_position(index_with_missing, na_position): with tm.maybe_produces_warning( PerformanceWarning, - pa_version_under7p0 - and getattr(index_with_missing.dtype, "storage", "") == "pyarrow", + getattr(index_with_missing.dtype, "storage", "") == "pyarrow", check_stacklevel=False, ): with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"): diff --git a/pandas/tests/io/parser/conftest.py b/pandas/tests/io/parser/conftest.py index 0462d1fe6da0b..cc9823fe3371e 100644 --- a/pandas/tests/io/parser/conftest.py +++ b/pandas/tests/io/parser/conftest.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import warnings import pytest @@ -26,7 +27,11 @@ def update_kwargs(self, kwargs): def read_csv(self, *args, **kwargs): kwargs = self.update_kwargs(kwargs) - return read_csv(*args, **kwargs) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", "Use pd.to_datetime instead.", FutureWarning + ) + return read_csv(*args, **kwargs) def read_csv_check_warnings( self, warn_type: type[Warning], warn_msg: str, *args, **kwargs diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index f804f7df06bb8..b64af2dd98bcb 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -70,7 +70,8 @@ def test_plot(self): ax = _check_plot_works(df.plot, use_index=True) self._check_ticks_props(ax, xrot=0) - _check_plot_works(df.plot, sort_columns=False) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + _check_plot_works(df.plot, sort_columns=False) _check_plot_works(df.plot, yticks=[1, 5, 10]) _check_plot_works(df.plot, xticks=[1, 5, 10]) _check_plot_works(df.plot, ylim=(-100, 100), xlim=(-100, 100)) From ccffed93ff0bd761f8eea1775afba779fd38ba03 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 2 Sep 2022 10:10:53 -0700 Subject: [PATCH 2/3] Revert incorrect filtering location --- pandas/tests/io/parser/conftest.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/tests/io/parser/conftest.py b/pandas/tests/io/parser/conftest.py index cc9823fe3371e..0462d1fe6da0b 100644 --- a/pandas/tests/io/parser/conftest.py +++ b/pandas/tests/io/parser/conftest.py @@ -1,7 +1,6 @@ from __future__ import annotations import os -import warnings import pytest @@ -27,11 +26,7 @@ def update_kwargs(self, kwargs): def read_csv(self, *args, **kwargs): kwargs = self.update_kwargs(kwargs) - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", "Use pd.to_datetime instead.", FutureWarning - ) - return read_csv(*args, **kwargs) + return read_csv(*args, **kwargs) def read_csv_check_warnings( self, warn_type: type[Warning], warn_msg: str, *args, **kwargs From 8570372306e05f2ce79791029979870818952967 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 2 Sep 2022 14:31:33 -0700 Subject: [PATCH 3/3] Undo pa version check --- pandas/tests/indexes/test_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index b8591ab3a1532..c81b3a533170e 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -468,7 +468,8 @@ def test_hasnans_isnans(self, index_flat): def test_sort_values_invalid_na_position(index_with_missing, na_position): with tm.maybe_produces_warning( PerformanceWarning, - getattr(index_with_missing.dtype, "storage", "") == "pyarrow", + pa_version_under7p0 + and getattr(index_with_missing.dtype, "storage", "") == "pyarrow", check_stacklevel=False, ): with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"):