You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RandomSampleImputer rejects scalar column name 0 for observation seeds #1104
RandomSampleImputer(seed="observation", random_state=0) rejects column name 0 during construction. The equivalent random_state=[0] works. Integer column names are supported, and 0 is the first column label of a pandas DataFrame created without explicit column names.
To Reproduce
importpandasaspdfromfeature_engine.imputationimportRandomSampleImputerX=pd.DataFrame([[1, None], [2, 1.0], [3, 2.0], [4, None]])
# Works: column 0 supplies each observation's seed.print(RandomSampleImputer(
variables=[1], seed="observation", random_state=[0]
).fit_transform(X)[1].tolist())
# [2.0, 1.0, 2.0, 1.0]# Raises ValueError before fit(), despite naming the same column.RandomSampleImputer(variables=[1], seed="observation", random_state=0)
The constructor tests the truthiness of random_state, so it treats the integer column name 0 as missing.
Expected behavior
Both forms should select column 0 and produce the same imputation. Absent seeding variables (None or an empty list/string) should retain their existing validation.
The existing Narwhals migration (#965) still has the same constructor guard. This report concerns the scalar integer column label on current main; it does not change the observation seed algorithm or backend support.
I am working on a small constructor validation fix with a regression comparing random_state=0 and [0]. The observation seed algorithm and backend migration remain unchanged.
Activity