alteryx / alteryx/evalml

Component API: explore alternatives to kwargs

Offen
#2,857 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
refactor spike
Vorherrschende Sprache
Python
Sterne
850
Forks
96
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

While adding a new component, I ran into this test and error, pasted below. My understanding of this test is that it tests whether or not kwargs make it into our component's `parameters` dictionary and then if there's a component object, whether or not it's set as an attribute on the component object.

I just wanted to raise two assumptions and whether or not they're necessary or even good practice:

1) If a user gives us an erroneous keyword argument such as "foo", should we really be keeping that as part of `component.parameters`?
2) We're assuming that **kwargs is passed to the component object. This is not true in the case of the LabelEncoder which does not take any arguments.

```
def test_components_init_kwargs():
for component_class in all_components():
try:
component = component_class()
except EnsembleMissingPipelinesError:
continue
if component._component_obj is None:
continue
if isinstance(component, StackedEnsembleBase):
continue

obj_class = component._component_obj.__class__.__name__
module = component._component_obj.__module__
importlib.import_module(module, obj_class)
patched = module + "." + obj_class + ".__init__"

def all_init(self, *args, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)

with patch(patched, new=all_init) as _:
component = component_class(test_arg="test")
component_with_different_kwargs = component_class(diff_test_arg="test")
> assert component.parameters["test_arg"] == "test"
if not isinstance(component, PolynomialDetrender):
assert component._component_obj.test_arg == "test"
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.