From 3be97b52a3e4eb1daa0a3314ba99260033f169a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 17 Jan 2026 13:56:39 +0000 Subject: [PATCH 1/5] Initial plan From 0ffe965ce43e7767c14ab8bcf434333f060986d7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 17 Jan 2026 14:05:23 +0000 Subject: [PATCH 2/5] Add test for auto_aggregate features deprecation warning and fix bug Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com> --- balance/utils/data_transformation.py | 2 +- tests/test_util_data_transformation.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/balance/utils/data_transformation.py b/balance/utils/data_transformation.py index e4147433e..fbb067d97 100644 --- a/balance/utils/data_transformation.py +++ b/balance/utils/data_transformation.py @@ -263,7 +263,7 @@ def auto_aggregate( if features is not None: warnings.warn( "features argument is unused, it will be removed in the future", - warnings.DeprecationWarning, + DeprecationWarning, stacklevel=2, ) diff --git a/tests/test_util_data_transformation.py b/tests/test_util_data_transformation.py index e61b36321..0cd7a9eba 100644 --- a/tests/test_util_data_transformation.py +++ b/tests/test_util_data_transformation.py @@ -325,6 +325,21 @@ def test_auto_aggregate(self) -> None: aggfunc="not_sum", ) + def test_auto_aggregate_features_deprecation(self) -> None: + """Test that auto_aggregate warns when features parameter is used. + + Tests that the deprecated 'features' parameter triggers a + DeprecationWarning when it is not None. + This covers line 264 in data_transformation.py. + """ + df = pd.DataFrame( + {"x": [1, 2, 3, 4], "y": [1, 1, 1, np.nan], "id": [1, 1, 2, 3]} + ) + + # Test that passing features parameter triggers deprecation warning + with self.assertWarns(DeprecationWarning): + balance_util.auto_aggregate(df, features=["x", "y"]) + def test_fct_lump_basic_functionality(self) -> None: """Test basic functionality of fct_lump for category lumping. From 57ce5577b02011ffd6134e9b117a525419946cf8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 17 Jan 2026 14:50:10 +0000 Subject: [PATCH 3/5] Fix flake8 linting errors: remove trailing whitespace Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com> --- tests/test_util_data_transformation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_util_data_transformation.py b/tests/test_util_data_transformation.py index 0cd7a9eba..f49a398b7 100644 --- a/tests/test_util_data_transformation.py +++ b/tests/test_util_data_transformation.py @@ -327,15 +327,15 @@ def test_auto_aggregate(self) -> None: def test_auto_aggregate_features_deprecation(self) -> None: """Test that auto_aggregate warns when features parameter is used. - - Tests that the deprecated 'features' parameter triggers a + + Tests that the deprecated 'features' parameter triggers a DeprecationWarning when it is not None. This covers line 264 in data_transformation.py. """ df = pd.DataFrame( {"x": [1, 2, 3, 4], "y": [1, 1, 1, np.nan], "id": [1, 1, 2, 3]} ) - + # Test that passing features parameter triggers deprecation warning with self.assertWarns(DeprecationWarning): balance_util.auto_aggregate(df, features=["x", "y"]) From 3e0abbb9eb2f26fc7317a974c6687fd3e37f8d4c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 17 Jan 2026 15:45:33 +0000 Subject: [PATCH 4/5] Add test to cover line 162 in data_transformation.py Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com> --- tests/test_util_data_transformation.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_util_data_transformation.py b/tests/test_util_data_transformation.py index f49a398b7..07ec76f55 100644 --- a/tests/test_util_data_transformation.py +++ b/tests/test_util_data_transformation.py @@ -10,6 +10,7 @@ import balance.testutil import numpy as np import pandas as pd +from unittest.mock import patch # TODO: remove the use of balance_util in most cases, and just import the functions to be tested directly from balance import util as balance_util @@ -206,6 +207,36 @@ def test_quantize_non_numeric_series_raises(self) -> None: pd.Series(["x", "y", "z"]), ) + def test_quantize_non_dataframe_raises(self) -> None: + """Test that quantize raises TypeError when pd.Series returns non-Series object. + + This test covers line 162 in data_transformation.py by mocking pd.Series + to return an object that is neither a Series nor a DataFrame. + This is an edge case that can only occur if pd.Series is monkey-patched + or behaves unexpectedly. + """ + # Create a class that is neither Series nor DataFrame + class NotASeriesOrDataFrame: + pass + + # Create a metaclass that makes pd.Series return NotASeriesOrDataFrame + # but keeps it as a type for isinstance checks + class SeriesMeta(type): + def __call__(cls, *args, **kwargs): + return NotASeriesOrDataFrame() + + class FakeSeries(metaclass=SeriesMeta): + pass + + # Mock pd.Series to use our fake series class + with patch("balance.utils.data_transformation.pd.Series", FakeSeries): + self.assertRaisesRegex( + TypeError, + "df must be a pandas DataFrame", + balance_util.quantize, + 123, # Input that's not Series or DataFrame + ) + def test_row_pairwise_diffs(self) -> None: d = pd.DataFrame({"a": (1, 2, 3), "b": (-42, 8, 2)}) e = pd.DataFrame( From a8227edefdb5d002a4b0f7e3a7894bb7d2493c52 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:41:20 +0000 Subject: [PATCH 5/5] Fix ufmt formatting: reorder imports and add blank line Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com> --- tests/test_util_data_transformation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_util_data_transformation.py b/tests/test_util_data_transformation.py index 07ec76f55..a47f01537 100644 --- a/tests/test_util_data_transformation.py +++ b/tests/test_util_data_transformation.py @@ -7,10 +7,11 @@ from __future__ import annotations +from unittest.mock import patch + import balance.testutil import numpy as np import pandas as pd -from unittest.mock import patch # TODO: remove the use of balance_util in most cases, and just import the functions to be tested directly from balance import util as balance_util @@ -215,6 +216,7 @@ def test_quantize_non_dataframe_raises(self) -> None: This is an edge case that can only occur if pd.Series is monkey-patched or behaves unexpectedly. """ + # Create a class that is neither Series nor DataFrame class NotASeriesOrDataFrame: pass