alteryx / alteryx/evalml

DatetimeFeaturizer: common code in _extract funcs

Offen
#2,934 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @asniyaz Auf GitHub ansehen
refactor
Vorherrschende Sprache
Python
Sterne
850
Forks
96
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

datetime_featurizer.py has two functions that are the same, but use different mapping dictionaries. After both these functions were updated in the same fashion to complete the #2909 WW 0.8.2 upgrade, we should probably refactor these to be the same function but accepting a mapping dictionary.

```
def _extract_month(col, encode_as_categories=False):
months = col.dt.month_name()
months_unique = months.unique()
months_encoded = months.map(lambda m: _month_to_int_mapping.get(m, np.nan))
if encode_as_categories:
months_encoded = ww.init_series(months_encoded, logical_type="Categorical")
return months_encoded, {
m: _month_to_int_mapping.get(m, np.nan) for m in months_unique
}

def _extract_day_of_week(col, encode_as_categories=False):
days = col.dt.day_name()
days_unique = days.unique()
days_encoded = days.map(lambda d: _day_to_int_mapping.get(d, np.nan))
if encode_as_categories:
days_encoded = ww.init_series(days_encoded, logical_type="Categorical")
return days_encoded, {d: _day_to_int_mapping.get(d, np.nan) for d in days_unique}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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