FaissImputer
Warning: FaissImputer 0.1.x has a known neighbor-mapping bug that can produce incorrect imputations, and it is incompatible with scikit-learn 1.8+. Use version 0.2.0 or newer.
Impute missing values using Meta's faiss - A Python library for missing data imputation with k nearest neighbors.
What's new in 0.2.2
- Clears fitted state after a failed
fit(), including failed refits. - Corrects scikit-learn transformer, NaN-support, and
float32dtype-preservation tags. - Adds regression tests for failed fits, estimator tags, and pipeline use.
See the 0.2.2 release notes for details.
What's new in 0.2.1
Version 0.2.1 is a packaging and documentation hotfix. The imputation behavior is unchanged from 0.2.0.
- Corrects the PyPI description so it no longer presents 0.2.0 as unreleased.
- Uses portable warning markup and absolute documentation links that work on PyPI.
- Verifies built package metadata against the release tag before publication.
See the 0.2.1 release notes for the packaged changes.
What's new in 0.2.0
Version 0.2.0 is the corrected release recommended for users upgrading from 0.1.x.
- Corrects the neighbor-to-donor mapping that could return values from the wrong training row.
- Uses the donor rows learned during
fit()when new data is passed totransform(). - Searches for neighbors using only the columns observed in each query row.
- Preserves the input array and reuses fallback statistics learned during
fit(). - Supports modern scikit-learn validation APIs and adds regression tests and automatic CI.
Upgrade an existing installation with:
python -m pip install --upgrade "faiss-imputer>=0.2.2"
See the 0.2.0 release notes and the full benchmark report for details and current limitations.
Installation
You can install faiss-imputer using pip:
FaissImputer requires Python 3.10 or newer.
pip install faiss-imputer
Usage
import numpy as np
from faiss_imputer import FaissImputer
# Complete rows used as reference donors
X_train = np.array(
[
[1.0, 10.0, 100.0],
[2.0, 20.0, 200.0],
[3.0, 30.0, 300.0],
],
dtype=np.float32,
)
# New rows containing missing values
X_missing = np.array(
[
[1.5, np.nan, 150.0],
[2.5, 25.0, np.nan],
],
dtype=np.float32,
)
imputer = FaissImputer(n_neighbors=2)
imputer.fit(X_train)
X_imputed = imputer.transform(X_missing)
print(X_imputed)
transform() returns a NumPy float32 array. The input array is not modified.
Parameters
n_neighbors: Number of reference rows used to calculate each missing value.metric: Neighbor-search metric. Supported values are"l2"and"ip". Raw inner product is not cosine similarity.strategy: Aggregation method for neighbor values. Supported values are"mean"and"median".index_factory: Faiss index description. The default"Flat"performs exact search.
Important behavior
fit()currently uses only rows without any missing values as reference donors.- Neighbor search compares only the columns observed in each query row.
n_neighborscannot exceed the number of complete reference rows.- An entirely missing row is filled using statistics learned during
fit(). - Input data must be a two-dimensional numeric array with the same number of columns used during
fit().
Benchmark
In a controlled synthetic benchmark with complete training donors, FaissImputer 0.2.0 and scikit-learn's KNNImputer produced exactly matching imputed values. With 20,000 training rows, FaissImputer transformed repeated missingness patterns up to 19.62 times faster, while performance was effectively tied when almost every test row had a different pattern.
When the training data itself contained missing values, FaissImputer was less accurate because version 0.2.0 uses only fully observed rows as donors. These single-thread results are specific to the tested synthetic data and hardware, not a general performance guarantee.
See the full 0.2.0 benchmark report, reproduction script, and raw results. Planned improvements are tracked in the roadmap.
Example notebook
See Imputing Missing Values with Faiss Imputer for a notebook example.
Contributing
Contributions are welcome! If you find a bug or have an enhancement suggestion, please open an issue or create a pull request.
Author
- GitHub: @ScionKim
License
This project is licensed under the MIT License.
Third-Party Licenses
FaissImputer depends on Meta's Faiss, which is distributed under the MIT License.
FaissImputer is not affiliated with or endorsed by Meta or the Faiss maintainers.
For detailed licensing information of the Faiss library, please refer to the Faiss repository.
Metadata
Release files for faiss-imputer 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| faiss_imputer-0.2.2.tar.gz | 8.0 kB | With provenance | Details for faiss_imputer-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| faiss_imputer-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for faiss_imputer-0.2.2-py3-none-any.whl |
Total release size: 14.8 kB
Release files / faiss_imputer-0.2.2.tar.gz
| Download URL | faiss_imputer-0.2.2.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cab4c941b0b720042686a66ac807cb05e6d9f0e93f77eeacbf2fdfe2202d0869
|
|
BLAKE2b-256 checksum How to use checksums |
622597346876fd14b9ff981811b3163fd00fc1ab3c166abf245245f830ff153d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / faiss_imputer-0.2.2-py3-none-any.whl
| Download URL | faiss_imputer-0.2.2-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c67a09c336f90509fb614261088566887adfcfda860f540831bdbce233f133e2
|
|
BLAKE2b-256 checksum How to use checksums |
7cd6c14dcc5ffc4e93841f9f2f4f71c7d0c7a3690db8e80c26fbede374dfaeb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logSecurity for faiss-imputer 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for faiss_imputer-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.