Skip to content

Reduce Warnings#766

Merged
Scienfitz merged 19 commits intomainfrom
refactor/avoid_warnings
Mar 30, 2026
Merged

Reduce Warnings#766
Scienfitz merged 19 commits intomainfrom
refactor/avoid_warnings

Conversation

@Scienfitz
Copy link
Copy Markdown
Collaborator

@Scienfitz Scienfitz commented Mar 19, 2026

This is mostly a housekeeping PR aimed at reducing unnecessary warnings. Examples are for instance unnecessary tensor or integer conversion, pandas behavior that is deprecated etc.

Two sources of warnings have not been touched:

  • Use of Dummy in discrete constraints: FutureWarning from pandas but likely more complex to fix
  • test_deprecations uses construction of objects in parameterization that is deprecated. Since this happens before code execution warnings filters did not have any effect on this (including a file wide pytestmark)

A full run of all tests with pytest -vv leads to 246 warnings on a fairly up to date dev environment versus 722 warnings previously.

@Scienfitz Scienfitz self-assigned this Mar 19, 2026
Copilot AI review requested due to automatic review settings March 19, 2026 12:07
Copy link
Copy Markdown
Contributor

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

Housekeeping PR focused on reducing noisy/deprecated warnings across the codebase (tests, docs, and a couple of runtime utilities), mainly around pandas and torch behaviors.

Changes:

  • Suppress or avoid warnings in tests (e.g., UnusedObjectWarning, pandas dtype FutureWarnings, SHAP runtime warnings).
  • Adjust dataframe dtype normalization to avoid warning on integer-to-float conversions while still converting internally.
  • Avoid pandas FutureWarnings in constraint logic and docs examples (copying slices; avoiding concat with empty frames).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/validation/test_campaign_validation.py Suppresses UnusedObjectWarning during overlapping-name validation for non-predictive recommenders.
tests/utils/test_sampling_algorithms.py Conditionally suppresses the “All points are identical” warning in FPS property-based tests.
tests/utils/test_dataframe.py Adds an integer-valued “valid” case for dtype normalization tests.
tests/test_simulation.py Adds include_groups=False to silence pandas groupby/apply warnings.
tests/test_settings.py Suppresses UnusedObjectWarning during caching tests for non-predictive recommenders.
tests/test_kernels.py Replaces torch.tensor(...) with torch.as_tensor(...) to reduce tensor-construction warnings.
tests/test_input_output.py Uses .loc assignment and suppresses pandas FutureWarning for deliberate bad-dtype injections.
tests/serialization/test_json_serialization.py Ensures opened file handles are closed even when JSON decoding raises.
tests/insights/test_shap.py Suppresses SHAP-internal RuntimeWarning noise while still asserting expected UserWarnings.
docs/userguide/async.md Uses .copy() when slicing to avoid pandas chained-assignment/view warnings.
baybe/utils/dataframe.py Refines dtype normalization warning logic (don’t warn for integer columns, still convert).
baybe/constraints/discrete.py Avoids pandas FutureWarning by skipping concat with empty DataFrame parts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_simulation.py Outdated
@Scienfitz Scienfitz force-pushed the refactor/avoid_warnings branch from f018573 to 582e01f Compare March 19, 2026 12:26
Copy link
Copy Markdown
Collaborator

@AdrianSosic AdrianSosic left a comment

Choose a reason for hiding this comment

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

Thx!

Comment thread tests/insights/test_shap.py
Comment thread tests/utils/test_sampling_algorithms.py Outdated
Comment thread tests/validation/test_campaign_validation.py Outdated
Comment thread tests/test_settings.py Outdated
Comment thread docs/userguide/async.md Outdated
Comment thread docs/userguide/async.md
@Scienfitz Scienfitz force-pushed the refactor/avoid_warnings branch 3 times, most recently from 42a0a09 to 178066b Compare March 29, 2026 13:17
Scienfitz and others added 17 commits March 29, 2026 17:22
Integer columns for numerical parameters/targets are losslessly convertible to float and do not warrant a warning. Only truly problematic types (bool, object, string) now trigger InputDataTypeWarning.
Pandas deprecated concatenation behavior when empty DataFrames affect result dtype inference. Skip the empty DataFrame from concat when other_params is empty.
Copy the DataFrame slice before in-place modification to avoid pandas SettingWithCopyWarning.
…output

Replace df[col].iloc[0] with df.iloc[0, ...] to avoid pandas SettingWithCopyWarning and ChainedAssignmentError FutureWarning. Suppress the remaining incompatible dtype FutureWarning since it is an inherent side effect of deliberately assigning invalid values.
Add include_groups=False to groupby().apply() to avoid pandas FutureWarning about deprecated behavior of operating on grouping columns.
Avoid UserWarning about copying from an existing tensor when the value is already a torch.Tensor.
Close the file handle opened for the filelike channel to avoid ResourceWarning about unclosed files.
Use pytest.warns for expected UserWarnings about missing explanation_index (force/waterfall plots) and excluded non-numeric features (scatter plots). Suppress shap's own RuntimeWarnings.
The degenerate point cloud edge case is already explicitly tested in test_farthest_point_sampling_pathological_case. Suppress the warning in the general hypothesis-based test to avoid noise from randomly generated identical points.
Non-predictive recommenders warn when called with an objective. Suppress this expected side effect in tests that validate unrelated behavior (overlapping names, caching).
Using `apply` is suboptimal since it underwent various arg and default changes in different pandas versions. By avoiding `apply` and calling the validation explicitly it works in all pandas versions.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: AdrianSosic <adrian.sosic@merckgroup.com>
@Scienfitz Scienfitz force-pushed the refactor/avoid_warnings branch from 4550856 to 6e14288 Compare March 29, 2026 15:22
AdrianSosic and others added 2 commits March 30, 2026 14:25
Instead of silencing the warning, this fixes the cause of the issue
This section used deprecated functions and is obsolete as the random seeding is explained now in the settings user guide
@Scienfitz Scienfitz force-pushed the refactor/avoid_warnings branch from bf5f5aa to 23aa86f Compare March 30, 2026 12:46
@Scienfitz Scienfitz merged commit b9cd5c4 into main Mar 30, 2026
12 of 13 checks passed
@Scienfitz Scienfitz deleted the refactor/avoid_warnings branch March 30, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants