From 2305b8094473b64ba91c3ea811c6249167bf5c70 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 12 Aug 2022 22:56:16 -0700 Subject: [PATCH 1/5] TST: Address test warnings --- pandas/core/groupby/generic.py | 13 ++++++++++--- pandas/core/groupby/groupby.py | 2 +- pandas/tests/io/excel/test_readers.py | 2 ++ pandas/tests/io/excel/test_writers.py | 2 +- pandas/tests/reshape/merge/test_join.py | 5 +++-- pyproject.toml | 1 + 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 8a261f09e7118..fc05b73d4b0f7 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -973,9 +973,16 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame: result: dict[Hashable, NDFrame | np.ndarray] = {} if self.axis == 0: # test_pass_args_kwargs_duplicate_columns gets here with non-unique columns - for name, data in self: - fres = func(data, *args, **kwargs) - result[name] = fres + # test_pivot_margins_name_unicode gets here; avoid __iter__ single key + # deprecation + if len(self.keys) > 1: + for name, data in self: + fres = func(data, *args, **kwargs) + result[name] = fres + else: + single_key = self.keys[0] + fres = func(self[single_key], *args, **kwargs) + result[single_key] = fres else: # we get here in a number of test_multilevel tests for name in self.indices: diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 138474e21fb57..67f645c008ac3 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -828,7 +828,7 @@ def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ( "In a future version of pandas, a length 1 " "tuple will be returned when iterating over a " - "a groupby with a grouper equal to a list of " + "groupby with a grouper equal to a list of " "length 1. Don't supply a list with a single grouper " "to avoid this warning." ), diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 4ca34bec0a7d9..fa1d6bbfd5a7e 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -89,6 +89,7 @@ def _transfer_marks(engine, read_ext): for ext in read_ext_params if _is_valid_engine_ext_pair(eng, ext) ], + ids=str, ) def engine_and_read_ext(request): """ @@ -654,6 +655,7 @@ def test_read_excel_blank_with_header(self, read_ext): actual = pd.read_excel("blank_with_header" + read_ext, sheet_name="Sheet1") tm.assert_frame_equal(actual, expected) + @pytest.mark.filterwarnings("ignore:Cell A4 is marked:UserWarning:openpyxl") def test_date_conversion_overflow(self, request, engine, read_ext): # GH 10001 : pandas.ExcelFile ignore parse_dates=False if engine == "pyxlsb": diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index ba6366b71d854..4b0b0ee3a9070 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -878,7 +878,7 @@ def test_to_excel_output_encoding(self, ext): ) with tm.ensure_clean("__tmp_to_excel_float_format__." + ext) as filename: - df.to_excel(filename, sheet_name="TestSheet", encoding="utf8") + df.to_excel(filename, sheet_name="TestSheet") result = pd.read_excel(filename, sheet_name="TestSheet", index_col=0) tm.assert_frame_equal(result, df) diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index d97c6a3dacdc3..3befafd5fc5b4 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -736,8 +736,9 @@ def _check_join(left, right, result, join_col, how="left", lsuffix="_x", rsuffix left_grouped = left.groupby(join_col) right_grouped = right.groupby(join_col) - - for group_key, group in result.groupby(join_col): + for group_key, group in result.groupby( + join_col if len(join_col) > 1 else join_col[0] + ): l_joined = _restrict_to_columns(group, left.columns, lsuffix) r_joined = _restrict_to_columns(group, right.columns, rsuffix) diff --git a/pyproject.toml b/pyproject.toml index 67c56123a847c..80d4a0c90fcc3 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:Calling close():UserWarning:xlsxwriter", ] junit_family = "xunit2" markers = [ From 7ae03f31699c32430a5385fa02f3376470ba026a Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 12 Aug 2022 22:56:54 -0700 Subject: [PATCH 2/5] Trigger CI From d9b2e8893ae6ea258a8270fa4ebe0902db6213b5 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 13 Aug 2022 21:48:13 -0700 Subject: [PATCH 3/5] Fix some code paths for warnings --- pandas/core/groupby/generic.py | 13 +++---------- pandas/tests/reshape/merge/test_join.py | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index fc05b73d4b0f7..f1a8a70674582 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -973,16 +973,9 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame: result: dict[Hashable, NDFrame | np.ndarray] = {} if self.axis == 0: # test_pass_args_kwargs_duplicate_columns gets here with non-unique columns - # test_pivot_margins_name_unicode gets here; avoid __iter__ single key - # deprecation - if len(self.keys) > 1: - for name, data in self: - fres = func(data, *args, **kwargs) - result[name] = fres - else: - single_key = self.keys[0] - fres = func(self[single_key], *args, **kwargs) - result[single_key] = fres + for name, data in self.grouper.get_iterator(obj, self.axis): + fres = func(data, *args, **kwargs) + result[name] = fres else: # we get here in a number of test_multilevel tests for name in self.indices: diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 3befafd5fc5b4..6e87c221426c1 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -736,6 +736,7 @@ def _check_join(left, right, result, join_col, how="left", lsuffix="_x", rsuffix left_grouped = left.groupby(join_col) right_grouped = right.groupby(join_col) + for group_key, group in result.groupby( join_col if len(join_col) > 1 else join_col[0] ): From c6be8d890821c4a7501780131a0c1ba554d1cc81 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 14 Aug 2022 21:18:21 -0700 Subject: [PATCH 4/5] Fix test --- pandas/tests/groupby/test_groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index d290aada18293..a63e0df25b160 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2801,7 +2801,7 @@ def test_single_element_list_grouping(): ) msg = ( "In a future version of pandas, a length 1 " - "tuple will be returned when iterating over a " + "tuple will be returned when iterating over " "a groupby with a grouper equal to a list of " "length 1. Don't supply a list with a single grouper " "to avoid this warning." From 6765f8a3726dfe5be27c4badefbafec07099fad8 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 15 Aug 2022 12:30:55 -0700 Subject: [PATCH 5/5] add numba filters parallel warnings, more specific test filter --- pandas/tests/groupby/aggregate/test_numba.py | 1 + pandas/tests/groupby/transform/test_numba.py | 1 + pandas/tests/io/excel/test_writers.py | 1 + pyproject.toml | 1 - 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index 2890b7930611c..0b2fb56a02006 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -214,6 +214,7 @@ def func_kwargs(values, index): @td.skip_if_no("numba") +@pytest.mark.filterwarnings("ignore") def test_multiindex_one_key(nogil, parallel, nopython): def numba_func(values, index): return 1 diff --git a/pandas/tests/groupby/transform/test_numba.py b/pandas/tests/groupby/transform/test_numba.py index 0e26cdc294b55..2b70d7325a209 100644 --- a/pandas/tests/groupby/transform/test_numba.py +++ b/pandas/tests/groupby/transform/test_numba.py @@ -202,6 +202,7 @@ def func_kwargs(values, index): @td.skip_if_no("numba") +@pytest.mark.filterwarnings("ignore") def test_multiindex_one_key(nogil, parallel, nopython): def numba_func(values, index): return 1 diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 4b0b0ee3a9070..977f278b7d04c 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -1282,6 +1282,7 @@ def test_deprecated_attr(self, engine, ext, attr): # Some engines raise if nothing is written DataFrame().to_excel(writer) + @pytest.mark.filterwarnings("ignore:Calling close():UserWarning:xlsxwriter") @pytest.mark.parametrize( "attr, args", [("save", ()), ("write_cells", ([], "test"))] ) diff --git a/pyproject.toml b/pyproject.toml index 80d4a0c90fcc3..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:Calling close():UserWarning:xlsxwriter", ] junit_family = "xunit2" markers = [