alteryx / alteryx/evalml

DatetimeFeaturizer: common code in _extract funcs

Aperta
#2,934 0 commenti 0 reazioni 1 assegnatario Rivendicata da @asniyaz Vedi su GitHub
refactor
Lingua principale
Python
Stelle
850
Fork
96
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.