Skip to content

fix the conversion - #1

Open
xiaotong743 wants to merge 27 commits into
feat/api-simplificationfrom
feat/api-simplification-fix
Open

fix the conversion#1
xiaotong743 wants to merge 27 commits into
feat/api-simplificationfrom
feat/api-simplification-fix

Conversation

@xiaotong743

Copy link
Copy Markdown

Pandas refuses to assign a Categorical with categories different from the target's

selmanozleyen and others added 27 commits July 23, 2026 18:25
Scheme/Node/Bind data model, the annbatch-backed Loader and control-rooted
EvalLoader, obs factorization + in-memory materialization, and splitting, with
the data test suite. Data-only branch — foundation (nn/training) and metrics
live on the `rest` branch; this branch is meant to land on main on its own.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Keep the data branch focused on the training Loader; the control-rooted
EvalLoader (and its metrics-integration test) are deferred and will be re-added
later as a second loader reusing the shared _SchemeReader / _backend layer.
Removes _eval_loader.py, test_eval_loader.py, test_metrics_over_loader.py, and
the EvalLoader export.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Metrics moved here (off the data branch) so `data` stays a clean, data-only
unit to bring to main.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@selmanozleyen

Copy link
Copy Markdown
Collaborator

can you give me an example? ideally the datasets are preprocessed so that even if a categorical is not present in that dataset is should have under x_col.cats all the categories across datasets. See the unify.py file. This was we have common coding for each categories even if the files are separate. This gives us robustness because we would be tracking all the category space in all files.

@selmanozleyen

Copy link
Copy Markdown
Collaborator

Do you agree on this? Maybe I can make it clearer that I expect here in cateogoricals to have the same labeling metadata ie unified categoricals.

@xiaotong743

xiaotong743 commented Jul 26, 2026

Copy link
Copy Markdown
Author

To me this is an easy fix to make it more robust. It would be nice to make it explicit that one should unify the dataset in such a way. Maybe either have unify.py logic in also scfit instead of just cf-train and delete this logic here, or make it working now. Either way, I think we should fix this simply bc now it's not doing what it's intended to do.

import pandas as pd
from pandas.api.types import union_categoricals

fa = pd.DataFrame({"dataset": pd.Categorical(["ds_a"] * 3)})   # cats: ['ds_a']
fb = pd.DataFrame({"dataset": pd.Categorical(["ds_b"] * 3)})   # cats: ['ds_b']
union = union_categoricals([fa["dataset"], fb["dataset"]], ignore_order=True).categories
# union == ['ds_a', 'ds_b']

for f in (fa, fb):
    f.loc[:, "dataset"] = f["dataset"].cat.set_categories(union)
  # f["dataset"]        = f["dataset"].cat.set_categories(union) # fix

Output for pandas version >3
TypeError: Cannot set a Categorical with another, without identical categories

@selmanozleyen
selmanozleyen force-pushed the feat/api-simplification branch from ee4b393 to 43414a8 Compare July 27, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants