Skip to content

[python-package] simplify Dataset._compare_params_for_warning() - #6120

Merged
jameslamb merged 2 commits into
masterfrom
python/simplify-compare
Oct 3, 2023
Merged

jameslamb merged 2 commits into
masterfrom
python/simplify-compare

Conversation

@jameslamb

Copy link
Copy Markdown
Member

Contributes to #3756.

Private method Dataset._compare_for_warning() is used to avoid raising unnecessary warnings when creating a Dataset from another Dataset.

It's only used in one place:

https://github.com/microsoft/LightGBM/blob/63a882b7400a19485727cc808e4715897e63635a/python-package/lightgbm/basic.py#L2251-L2257

And that place only passes in results from Dataset.get_params().

Dataset.get_params() allways returns a dictionary (never None)...

https://github.com/microsoft/LightGBM/blob/63a882b7400a19485727cc808e4715897e63635a/python-package/lightgbm/basic.py#L1777

... so code paths in Dataset._compare_for_warning() to handle None are unnecessary.

This PR proposes removing them.

Notes for Reviewers

I found this by checking the statement coverage of the Python package's unit tests, like this:

sh build-python.sh install

SITE_PACKAGE_DIR=$(
    python -c "import site; print(site.getsitepackages()[0])"
)
pytest \
    --cov=${SITE_PACKAGE_DIR}/lightgbm \
    --verbose \
    tests/python_package_test/

coverage html
open ./htmlcov/index.html

Found through that that these if params is None blocks are not covered by any tests, and that was my clue that they might not be necessary at all.

@jmoralez

jmoralez commented Oct 2, 2023

Copy link
Copy Markdown
Collaborator

We should update the docstring as well

@jameslamb

Copy link
Copy Markdown
Member Author

We should update the docstring as well

ah yep, sorry about that.

updated in 63c38c0

@jameslamb
jameslamb merged commit f175ceb into master Oct 3, 2023
@jameslamb
jameslamb deleted the python/simplify-compare branch October 3, 2023 04:08
@github-actions

github-actions Bot commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants