Skip to content

Add test coverage for data_transformation.py and fix DeprecationWarning bug#274

Closed
Copilot wants to merge 5 commits intomainfrom
copilot/add-missing-tests-balance-utils
Closed

Add test coverage for data_transformation.py and fix DeprecationWarning bug#274
Copilot wants to merge 5 commits intomainfrom
copilot/add-missing-tests-balance-utils

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

  • Add test for quantize() TypeError when input is neither Series nor DataFrame (line 162) ✅
  • Add test for auto_aggregate() DeprecationWarning when features parameter is not None (line 264) ✅
  • Fix bug in auto_aggregate() where warnings.DeprecationWarning should be DeprecationWarning
  • Run tests to verify coverage improves from 98% to 100% ✅
  • Request code review ✅
  • Fix flake8 linting errors (trailing whitespace) ✅
  • Fix ufmt formatting (import order and blank lines) ✅

Summary

  • Coverage improved: 98% → 100% (2 missing lines → 0 missing lines)
  • Tests added:
    • test_auto_aggregate_features_deprecation covers the deprecation warning path (line 264)
    • test_quantize_non_dataframe_raises covers the edge case error handling (line 162)
  • Bug fixed: Corrected warnings.DeprecationWarning to DeprecationWarning in auto_aggregate()
  • Linting fixed: Removed trailing whitespace and fixed ufmt formatting
  • Line 162 coverage: Added test using mocking to simulate the edge case where pd.Series() returns an object that is neither a Series nor a DataFrame
Original prompt

This section details on the original issue you should resolve

<issue_title>[FEATURE] Add missing tests to balance/utils/data_transformation.py</issue_title>
<issue_description>Use these stats to help you:

Name Stmts Miss Cover Missing

balance/init.py 26 0 100%
balance/adjustment.py 136 7 95% 228, 245-249, 261, 294
balance/balancedf_class.py 278 13 95% 666-690, 1527, 2389-2396
balance/cli.py 283 39 86% 55-57, 101-103, 130, 159-160, 284, 322-359, 371-372, 375, 540-557, 563-564, 843-847
balance/csv_utils.py 16 0 100%
balance/datasets/init.py 37 0 100%
balance/sample_class.py 475 18 96% 145, 303, 308, 342, 345, 349-351, 524-525, 540, 854, 1104, 1620, 1695, 1838, 1878-1879
balance/stats_and_plots/init.py 0 0 100%
balance/stats_and_plots/general_stats.py 14 0 100%
balance/stats_and_plots/weighted_comparisons_plots.py 279 22 92% 658, 663-666, 672, 676, 699-700, 714, 888, 995, 1051, 1173, 1268, 1293-1295, 1304-1305, 1488-1491
balance/stats_and_plots/weighted_comparisons_stats.py 338 15 96% 299, 301, 303, 305, 308, 377, 777, 816, 832, 910, 949, 968, 1054, 1093, 1107
balance/stats_and_plots/weighted_stats.py 135 7 95% 67, 283, 287, 572, 677, 680, 683
balance/stats_and_plots/weights_stats.py 56 2 96% 249, 257
balance/testutil.py 93 6 94% 36-38, 207-210
balance/typing.py 6 0 100%
balance/util.py 10 0 100%
balance/utils/init.py 0 0 100%
balance/utils/data_transformation.py 132 2 98% 162, 264
balance/utils/file_utils.py 11 0 100%
balance/utils/input_validation.py 122 5 96% 108, 113, 188-189, 350
balance/utils/logging_utils.py 11 0 100%
balance/utils/model_matrix.py 178 2 99% 306, 362
balance/utils/pandas_utils.py 130 4 97% 100, 183, 186-187
balance/weighting_methods/init.py 0 0 100%
balance/weighting_methods/adjust_null.py 6 0 100%
balance/weighting_methods/cbps.py 181 10 94% 182, 184, 627-628, 689, 713, 726, 747, 765, 778
balance/weighting_methods/ipw.py 264 7 97% 90, 679, 683, 759, 807-813
balance/weighting_methods/poststratify.py 42 0 100%
balance/weighting_methods/rake.py 151 3 98% 97, 238, 327</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing tests to balance/utils/data_transformation.py Add test coverage for auto_aggregate deprecation warning and fix DeprecationWarning bug Jan 17, 2026
Copilot AI requested a review from talgalili January 17, 2026 14:07
@talgalili
Copy link
Contributor

@copilot

Fix

Run flake8 .
flake8 .
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.12.12/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.12.12/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.12/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.12/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.12/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.12.12/x64/lib
./tests/test_util_data_transformation.py:330:1: W293 blank line contains whitespace
./tests/test_util_data_transformation.py:331:66: W291 trailing whitespace
./tests/test_util_data_transformation.py:338:1: W293 blank line contains whitespace
Error: Process completed with exit code 1.

Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot

Fix
...

Fixed in commit 57ce557. Removed trailing whitespace from lines 330, 331, and 338 in the test file.

@talgalili talgalili marked this pull request as ready for review January 17, 2026 14:52
Copilot AI review requested due to automatic review settings January 17, 2026 14:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves test coverage for balance/utils/data_transformation.py from 98% to 99% by adding a test for the deprecation warning in auto_aggregate() and fixing a bug where warnings.DeprecationWarning was incorrectly used instead of the built-in DeprecationWarning class.

Changes:

  • Fixed bug in auto_aggregate() where warnings.DeprecationWarning should be DeprecationWarning
  • Added test coverage for the features parameter deprecation warning path in auto_aggregate()

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
balance/utils/data_transformation.py Fixed incorrect warnings.DeprecationWarning to DeprecationWarning in the auto_aggregate() function's deprecation warning
tests/test_util_data_transformation.py Added test_auto_aggregate_features_deprecation() to test the deprecation warning when the features parameter is used

@talgalili
Copy link
Contributor

@copilot
We are still missing a test to cover row 162 in
balance/utils/data_transformation.py

Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot
We are still missing a test to cover row 162 in
balance/utils/data_transformation.py
...

Added test in commit 3e0abbb. The test uses mocking to simulate the edge case where pd.Series() returns an object that is neither a Series nor DataFrame, which allows line 162 to be executed. Coverage is now 100% for data_transformation.py.

Copilot AI changed the title Add test coverage for auto_aggregate deprecation warning and fix DeprecationWarning bug Add test coverage for data_transformation.py and fix DeprecationWarning bug Jan 17, 2026
@talgalili
Copy link
Contributor

@copilot

Fix

Run ufmt check .
ufmt check .
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.12.12/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.12.12/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.12/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.12/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.12/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.12.12/x64/lib
Would format /home/runner/work/balance/balance/tests/test_util_data_transformation.py
✨ 1 file would be formatted, 53 files already formatted ✨
Error: Process completed with exit code 1.

Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot

Fix
...

Fixed in commit a8227ed. Applied ufmt formatting to reorder imports and add proper blank lines.

@meta-codesync
Copy link

meta-codesync bot commented Jan 17, 2026

@talgalili has imported this pull request. If you are a Meta employee, you can view this in D90921886.

@meta-codesync
Copy link

meta-codesync bot commented Jan 18, 2026

@talgalili merged this pull request in 2c0a324.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add missing tests to balance/utils/data_transformation.py

4 participants