From 24990176b16539e4be0201e62e84cb56cf4a9604 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 26 Aug 2022 22:12:14 +0200 Subject: [PATCH 1/9] CI: Catch importwarning _SixMetaPathImporter.find_spec --- ci/deps/actions-310.yaml | 2 +- pandas/tests/io/formats/test_format.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ci/deps/actions-310.yaml b/ci/deps/actions-310.yaml index d986a289ad75a..f5d7e78feb389 100644 --- a/ci/deps/actions-310.yaml +++ b/ci/deps/actions-310.yaml @@ -1,4 +1,4 @@ -name: pandas-dev +name: pandas-dev-test channels: - conda-forge dependencies: diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index a7c9c86b3d9a5..a5d139a8ac41c 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -3385,6 +3385,12 @@ def test_filepath_or_buffer_arg( getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) elif encoding == "foo": expected_warning = FutureWarning if method == "to_latex" else None + if ( + method == "to_string" + and data == "abc" + and filepath_or_buffer_id == "string" + ): + expected_warning = ImportWarning with tm.assert_produces_warning(expected_warning): with pytest.raises(LookupError, match="unknown encoding"): getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) From 8ad13f3d36b64b46977b05cd6df71d28eea5f6c8 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 26 Aug 2022 22:12:40 +0200 Subject: [PATCH 2/9] CI: Catch importwarning _SixMetaPathImporter.find_spec --- ci/deps/actions-310.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/deps/actions-310.yaml b/ci/deps/actions-310.yaml index f5d7e78feb389..d986a289ad75a 100644 --- a/ci/deps/actions-310.yaml +++ b/ci/deps/actions-310.yaml @@ -1,4 +1,4 @@ -name: pandas-dev-test +name: pandas-dev channels: - conda-forge dependencies: From 6679835c5e7d41ef3d14232a8b3742377131d866 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 26 Aug 2022 23:17:02 +0200 Subject: [PATCH 3/9] Add to filterwarnings --- pandas/tests/io/formats/test_format.py | 6 ------ pyproject.toml | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index a5d139a8ac41c..a7c9c86b3d9a5 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -3385,12 +3385,6 @@ def test_filepath_or_buffer_arg( getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) elif encoding == "foo": expected_warning = FutureWarning if method == "to_latex" else None - if ( - method == "to_string" - and data == "abc" - and filepath_or_buffer_id == "string" - ): - expected_warning = ImportWarning with tm.assert_produces_warning(expected_warning): with pytest.raises(LookupError, match="unknown encoding"): getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) diff --git a/pyproject.toml b/pyproject.toml index 67c56123a847c..db9766ca2223e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ filterwarnings = [ "ignore:pandas.util.testing is deprecated:FutureWarning:importlib", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", + "ignore:_SixMetaPathImporter.find_spec:ImportWarning:importlib", ] junit_family = "xunit2" markers = [ From 45717181c3e285dd4ea16c431d7cc48a677f35d6 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 27 Aug 2022 00:22:56 +0200 Subject: [PATCH 4/9] Adjust toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index db9766ca2223e..3172369be7bab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ filterwarnings = [ "ignore:pandas.util.testing is deprecated:FutureWarning:importlib", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", - "ignore:_SixMetaPathImporter.find_spec:ImportWarning:importlib", + "ignore:_SixMetaPathImporter.find_spec:ImportWarning", ] junit_family = "xunit2" markers = [ From dc9fcb1dbccca7c32a688d386aa8fc2217c37a25 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 27 Aug 2022 10:33:36 +0200 Subject: [PATCH 5/9] Fix warning --- pandas/tests/io/formats/test_format.py | 19 +++++++++++++++---- pyproject.toml | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index a7c9c86b3d9a5..3646fd0992b1e 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -19,6 +19,7 @@ from pandas.compat import ( IS64, + PY310, is_platform_windows, ) import pandas.util._test_decorators as td @@ -3384,10 +3385,20 @@ def test_filepath_or_buffer_arg( ): getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) elif encoding == "foo": - expected_warning = FutureWarning if method == "to_latex" else None - with tm.assert_produces_warning(expected_warning): - with pytest.raises(LookupError, match="unknown encoding"): - getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) + if ( + method == "to_string" + and data == "abc" + and filepath_or_buffer_id == "string" + and PY310 + ): + with tm.assert_produces_warning(ImportWarning, check_stacklevel=False): + with pytest.raises(LookupError, match="unknown encoding"): + getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) + else: + expected_warning = FutureWarning if method == "to_latex" else None + with tm.assert_produces_warning(expected_warning): + with pytest.raises(LookupError, match="unknown encoding"): + getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) else: expected = getattr(df, method)() getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) diff --git a/pyproject.toml b/pyproject.toml index 3172369be7bab..67c56123a847c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,6 @@ filterwarnings = [ "ignore:pandas.util.testing is deprecated:FutureWarning:importlib", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", - "ignore:_SixMetaPathImporter.find_spec:ImportWarning", ] junit_family = "xunit2" markers = [ From 17f6836375f96d874bde22fa0d3a748e7825027b Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 27 Aug 2022 10:35:59 +0200 Subject: [PATCH 6/9] Add comment --- pandas/tests/io/formats/test_format.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 3646fd0992b1e..e196f864548e5 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -3391,6 +3391,7 @@ def test_filepath_or_buffer_arg( and filepath_or_buffer_id == "string" and PY310 ): + # raises importwarning _SixMetaPathImporter.find_spec with tm.assert_produces_warning(ImportWarning, check_stacklevel=False): with pytest.raises(LookupError, match="unknown encoding"): getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) From 597edd2e22b5d322fe03658aba673751a2a1287d Mon Sep 17 00:00:00 2001 From: Patrick Hoefler <61934744+phofl@users.noreply.github.com> Date: Sat, 27 Aug 2022 12:40:46 +0200 Subject: [PATCH 7/9] Create test_format.py --- pandas/tests/io/formats/test_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index e196f864548e5..06a0901c9c8fb 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -3392,7 +3392,7 @@ def test_filepath_or_buffer_arg( and PY310 ): # raises importwarning _SixMetaPathImporter.find_spec - with tm.assert_produces_warning(ImportWarning, check_stacklevel=False): + with tm.maybe_produces_warning(ImportWarning, check_stacklevel=False): with pytest.raises(LookupError, match="unknown encoding"): getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) else: From 9f19cbbd6378c4eeb53a349f915baeebc5e094aa Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 27 Aug 2022 19:49:10 +0200 Subject: [PATCH 8/9] Add checks --- pandas/tests/io/formats/test_format.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index e196f864548e5..36e8e9d2264f5 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -20,6 +20,8 @@ from pandas.compat import ( IS64, PY310, + PY311, + is_numpy_dev, is_platform_windows, ) import pandas.util._test_decorators as td @@ -3390,6 +3392,8 @@ def test_filepath_or_buffer_arg( and data == "abc" and filepath_or_buffer_id == "string" and PY310 + and not PY311 + and not is_numpy_dev ): # raises importwarning _SixMetaPathImporter.find_spec with tm.assert_produces_warning(ImportWarning, check_stacklevel=False): From 82bcddc21a147c7e4ab80bdecda291f89191a24b Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 27 Aug 2022 19:49:25 +0200 Subject: [PATCH 9/9] Fix --- pandas/tests/io/formats/test_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 7b28d547da620..36e8e9d2264f5 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -3396,7 +3396,7 @@ def test_filepath_or_buffer_arg( and not is_numpy_dev ): # raises importwarning _SixMetaPathImporter.find_spec - with tm.maybe_produces_warning(ImportWarning, check_stacklevel=False): + with tm.assert_produces_warning(ImportWarning, check_stacklevel=False): with pytest.raises(LookupError, match="unknown encoding"): getattr(df, method)(buf=filepath_or_buffer, encoding=encoding) else: