Repository navigation
feat: add CategoricalEncoder (one-hot / ordinal, handle_unknown) - #12
Conversation
Encodes object, string and category columns using sorted categories learned in fit; numeric columns pass through. Overrides get_feature_names_out for the generated one-hot columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover both methods, unknown handling, validation, missing values, name collisions, get_feature_names_out and scikit-learn compatibility. Compute codes with Index.get_indexer, since building a Categorical from values outside its categories is deprecated in pandas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Nice work. CI is green and all 60 tests pass. Two things before merge:
Eline sağlık Eren, CI yeşil ve 60 testin hepsi geçiyor. Merge'den önce iki küçük şey var:
Not: #11 de init.py dosyasını değiştiriyor. Önce #11'i merge edeceğiz, sonra burada küçük bir rebase gerekecek: iki import satırı ve all içinde iki isim yan yana kalacak. |
…coder # Conflicts: # src/preprocessing_toolkit/__init__.py
Category dtype columns now use their declared categories, so ordered categoricals keep their order and unused levels are kept. Mixed-type object columns no longer crash in sorted(); they fall back to sorting by string value, with the type name breaking ties. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Both are fixed:
I also merged main into the branch to resolve the Teşekkürler! İki düzeltmeyi de yaptım:
Ayrıca |
|
Thanks Eren, both fixes verified. Teşekkürler!” |
Closes #3
Summary
Adds
CategoricalEncoder, the block that turns categorical columns into numbers.method="onehot"(default) replaces each categorical column, in place, with one 0/1 integer column per category, named<column>_<category>.method="ordinal"replaces it with the category's position incategories_[column].fitonly, sorted, and stored incategories_as{column: [category, ...]}.transform:handle_unknown="error"raises aValueErrornaming the column and values;"ignore"gives all zeros (one-hot) or-1(ordinal).get_feature_names_out; it reuses the base class checks for fitted state andinput_features.Acceptance criteria
BasePreprocessor, implements only_fit/_transform;__init__only stores its arguments.method/handle_unknownraiseValueErrorinfit.ValueErrorinfitandtransform, asking to impute first.ValueErrorinfit.get_feature_names_out()matches the columnstransformproduces for both methods.transformreturns a new DataFrame and does not modify its input (index is kept).make_pipeline+cross_val_score;GridSearchCVtunesmethod.preprocessing_toolkit.ruff check,ruff format --check,pytestpass locally (60 tests, Python 3.13).Notes
pd.Index(categories).get_indexer(values); building apd.Categoricalfrom values outside its categories is deprecated in recent pandas.__init__.pywill need a trivial merge with feat: add missing value imputer #10 (imputer export) depending on merge order.🤖 Generated with Claude Code