Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.1MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
KNNImputer
✓ from missingpy import KNNImputer
✗ from missingpy import KNNImputer
This quickstart demonstrates how to use `MissForest` to impute missing values (represented by `np.nan`) in a NumPy array. It includes the necessary workaround for `scikit-learn` compatibility that is commonly required. Ensure categorical variables are one-hot encoded before passing them to the imputer.
import numpy as np
# Workaround for scikit-learn compatibility
import sklearn.neighbors._base
import sys
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
from missingpy import MissForest
nan = np.nan
X = np.array([
[1, 2, nan],
[3, 4, 3],
[nan, 6, 5],
[8, 8, 7]
])
imputer = MissForest(random_state=42)
X_imputed = imputer.fit_transform(X)
print("Original Data with NaNs:\n", X)
print("Imputed Data:\n", X_imputed)
Debug
Known issues
breakingMissingPy has severe compatibility issues with recent versions of `scikit-learn` (e.g., >=1.0) due to reliance on internal `sklearn.neighbors` modules that have been reorganized or removed. This often leads to `ImportError`.fixUse a compatibility workaround by aliasing `sys.modules['sklearn.neighbors.base']` before importing `missingpy` classes. Additionally, pinning `scikit-learn` to an older, compatible version (e.g., `scikit-learn==1.1.2` or lower) and `scipy==1.9.1` is often required.
affects: missingpy==0.2.0 with scikit-learn >= 1.0
gotchaMissingPy's `MissForest` algorithm expects numerical input. If your dataset contains categorical variables, they must be explicitly one-hot encoded (dummy encoded) before passing them to the imputer, otherwise, it will raise an error like 'could not convert string to float'.fixManually one-hot encode categorical columns using `pandas.get_dummies` or `sklearn.preprocessing.OneHotEncoder` before imputation.
affects: All versions
gotchaThe `missingpy` library is no longer actively maintained. The last PyPI release was in December 2018, and the GitHub repository shows minimal activity since. This means there will likely be no official updates for newer Python versions, `scikit-learn` compatibility, or bug fixes.fixBe aware of potential future incompatibilities with newer Python ecosystem libraries. Consider alternative, actively maintained imputation libraries for long-term projects.
affects: All versions (due to lack of future updates)
Upgrade
Version history
0.2.0latest on PyPI · released Dec 10, 2018
Audit
Dependencies
numpyrequiredFundamental array operations and data structures.
scipyrequiredScientific computing and advanced mathematical operations.
scikit-learnrequiredAPI compatibility and underlying machine learning utilities.
pandasrequiredData manipulation, especially for handling DataFrames.