Skip to content

[ENH] object config interface#140

Merged
RNKuhns merged 11 commits into
mainfrom
object-config
Mar 9, 2023
Merged

[ENH] object config interface#140
RNKuhns merged 11 commits into
mainfrom
object-config

Conversation

@fkiraly
Copy link
Copy Markdown
Contributor

@fkiraly fkiraly commented Mar 4, 2023

port of sktime/sktime#3822 to skbase

This PR adds a config management capabilities to all sktime objects, similar to sklearn's new config interface, via two methods get_config and set_config.

It is based on the flag manager mixin introduced in sktime/sktime#3630 (ported to skbase in #138)

A STEP is available here: sktime/enhancement-proposals#29

Includes:

  • test for get_config and set_config interface

@fkiraly fkiraly added the implementing framework Implementing core skbase framework label Mar 4, 2023
Comment thread skbase/tests/test_base.py
assert not fixture_class_parent_instance._has_implementation_of("some_method")


class ConfigTester(BaseObject):

Check warning

Code scanning / CodeQL

`__eq__` not overridden when adding attributes

The class 'ConfigTester' does not override ['__eq__'](1), but adds the new attribute [a](2). The class 'ConfigTester' does not override ['__eq__'](1), but adds the new attribute [b](3). The class 'ConfigTester' does not override ['__eq__'](1), but adds the new attribute [c](4).
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 4, 2023

Codecov Report

Merging #140 (adcf23b) into main (3cd2cbb) will increase coverage by 0.04%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #140      +/-   ##
==========================================
+ Coverage   82.64%   82.68%   +0.04%     
==========================================
  Files          32       32              
  Lines        2316     2322       +6     
==========================================
+ Hits         1914     1920       +6     
  Misses        402      402              
Impacted Files Coverage Δ
skbase/base/_base.py 82.22% <100.00%> (+0.40%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Copy Markdown
Contributor

@RNKuhns RNKuhns left a comment

Choose a reason for hiding this comment

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

@fkiraly I'm fine with the logic and implementations. But can you go through the docstrings to make sure they follow the numpydoc API.

Otherwise they generate lots of formatting errors/warnings when rendered by sphinx (makes it tough to understand success or failure of actual doc buildingg/formatting)

Comment thread skbase/base/_tagmanager.py Outdated

Parameters
----------
flag_attr_name : str, optional, default = "_flags"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor tweak, but numpydoc notes that if the default value is used then you don't put "optional" part of parameter docstring (e.g., you'd just put flag_attr_name : str, default="_flags").

They also show no spaces around equal sign.

Can you take a quick look at the docstrings in the PR and update these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, you would use "optional" only if you have sth like None. Fixed in all parallel cases


Returns
-------
collected_flags : dict
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per numpydoc if there is only a single return, just the return type can be listed on first line of "returns" description.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you take a look at the returns section of all the docstrings in this PR for conformity with this.

Comment thread skbase/base/_tagmanager.py Outdated
Parameters
----------
flag_name : str
Name of flag to be retrieved
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The description lines for parameters should end with periods (e.g., Name of flag to be retrieved).

Can you take a look through docstrings in the PR and make sure the periods are there?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See examples at numpydoc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, fixed in all instances.

Comment thread skbase/base/_tagmanager.py Outdated

Raises
------
ValueError if raise_error is True i.e. if flag_name is not in self.get_flags(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move the description of when the ValueError is raised to the line below the error type (and indent like other descriptions).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread skbase/base/_tagmanager.py Outdated

Returns
-------
Self : Reference to self.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move return type description to line below return type (and remove colon).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, done

Comment thread skbase/base/_tagmanager.py Outdated

Returns
-------
Self :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same

Comment thread skbase/base/_base.py
return self

update_dict = {key: tags_est[key] for key in tag_names}
def get_config(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a blocking change, but just noting that later we'll want to generalize get_config to get global config and local config (currently only handles local config).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm, I thought the future logic was going to be, local config overrides global config, and the return is global.update(local)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fkiraly that's actually what I meant. We'll need an extension point so that we users can specify global config locations that implement something that aligns with the protocol (e.g, can point to their own packages global get_config). The idea would be to get skbase global configs, user global configs and then local configs.

Analagous to walking the MRO and collecting tags, but walking specified global configs.

@fkiraly
Copy link
Copy Markdown
Contributor Author

fkiraly commented Mar 8, 2023

I think I've addressed all the above, including parallel locations.

Btw, if we lint numpydoc, should we not have it as part of the CI?
I was only loosely following numpydoc, deviating where I thought it made things more obscure (e.g., return variable name or "optional")

@fkiraly fkiraly requested a review from RNKuhns March 8, 2023 18:29
@fkiraly fkiraly mentioned this pull request Mar 8, 2023
@RNKuhns
Copy link
Copy Markdown
Contributor

RNKuhns commented Mar 9, 2023

I think I've addressed all the above, including parallel locations.

Btw, if we lint numpydoc, should we not have it as part of the CI? I was only loosely following numpydoc, deviating where I thought it made things more obscure (e.g., return variable name or "optional")

@fkiraly I've opened the issue. And it looks like our thoughts on this are timely. There is a new PR in numpydoc repo to allow its validate functionality to be used in a pre-commit hook!

Copy link
Copy Markdown
Contributor

@RNKuhns RNKuhns left a comment

Choose a reason for hiding this comment

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

LGTM.

@RNKuhns RNKuhns merged commit 39f6adf into main Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

implementing framework Implementing core skbase framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants