skbase icon indicating copy to clipboard operation
skbase copied to clipboard

[ENH] change `_MetaObjectMixin._check_objects` default for `attr_name` to auto-detect

Open SimonBlanke opened this issue 3 months ago • 7 comments

Reference Issues/PRs

Closes #159

What does this implement/fix? Explain your changes.

Sets attr_name to None and auto detect from "named_object_parameters" of attr_name remains None

Does your contribution introduce a new dependency? If yes, which one?

What should a reviewer concentrate their feedback on?

Any other comments?

PR checklist

For all contributions
  • [ ] I've reviewed the project documentation on contributing
  • [ ] I've added myself to the list of contributors.
  • [ ] The PR title starts with either [ENH], [CI/CD], [MNT], [DOC], or [BUG] indicating whether the PR topic is related to enhancement, CI/CD, maintenance, documentation, or a bug.
For code contributions
  • [ ] Unit tests have been added covering code functionality
  • [ ] Appropriate docstrings have been added (see documentation standards)
  • [ ] New public functionality has been added to the API Reference

SimonBlanke avatar Nov 06 '25 20:11 SimonBlanke

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 84.83%. Comparing base (306958d) to head (d47c6b2). :warning: Report is 167 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #466      +/-   ##
==========================================
- Coverage   85.07%   84.83%   -0.24%     
==========================================
  Files          45       51       +6     
  Lines        3015     3825     +810     
==========================================
+ Hits         2565     3245     +680     
- Misses        450      580     +130     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Nov 06 '25 20:11 codecov[bot]

added a test 'test_check_objects_attr_name_explicit'. The asserts are not that useful, but it at least covers some additional code if attr_name is not None

SimonBlanke avatar Nov 08 '25 05:11 SimonBlanke

added another test 'test_check_objects_attr_name_custom_tag'. It sets a custom tag via set_tags.

I just realized, that I used a private method _check_objects for the tests. Normally, that should be a no-go, but it seems the method is not used anywhere else in the package.

SimonBlanke avatar Nov 08 '25 05:11 SimonBlanke

@fkiraly I improved the test quality by triggering an error in each test and catching the error type.

SimonBlanke avatar Nov 08 '25 06:11 SimonBlanke

I think the coupling to self should happen at least one layer higher, i.e., not in the checker function, but where it is being called.

Otherwise we have intransparent coupling in a function that looks like a pure function but actually is not.

I understand we have some hidden coupling going on in _check_objects. The method signature does not reveal how it works. The tags are surprisingly read without the user knowing. From your explanation I infer the problem is, that some high level orchestration stuff (object stats, method calls) is mixed with lower level logic. It would help if we separate this.

I'll think about how to solve this.

SimonBlanke avatar Nov 29 '25 06:11 SimonBlanke

that some high level orchestration stuff (object stats, method calls) is mixed with lower level logic. It would help if we separate this.

Yes, exactly - are there any other tags that get read in there?

fkiraly avatar Nov 29 '25 09:11 fkiraly

are there any other tags that get read in there?

No, I only see attr_name = self.get_tag("named_object_parameters") here. For the decoupling I would like to separate the code into the following methods:

def _check_objects(self, objs, attr_name=None, ...):
    """Orchestration/high-level layer."""
    if attr_name is None:
        attr_name = self.get_tag("named_object_parameters")

    validated = self._validate_objects(objs, attr_name, ...)
    return self._coerce_to_named_object_tuples(validated, ...)

@staticmethod
def _validate_objects(objs, attr_name, cls_type=None, ...):
    # All validation logic

SimonBlanke avatar Nov 29 '25 11:11 SimonBlanke

okay there is a lot going on here (or maybe this is just in my head). First I added this note, because _check_objects does not really make sense to me as a private method, right now.

_validate_objects is a staticmethod now containing all the validation logic, _check_objects handles the rest. I also added a lot of comments. It feels necessary here.

SimonBlanke avatar Dec 15 '25 19:12 SimonBlanke

There is a linter error in a file I did not change: "skbase/tests/test_base.py:389:5: B043 Do not call delattr with a constant attribute value, it is not any safer than normal property access."

SimonBlanke avatar Dec 15 '25 19:12 SimonBlanke

There is a linter error in a file I did not change: "skbase/tests/test_base.py:389:5: B043 Do not call delattr with a constant attribute value, it is not any safer than normal property access."

fixed!

SimonBlanke avatar Dec 15 '25 20:12 SimonBlanke