Skip to content
المشاريع

حول

PyGrinder: a Python toolkit for grinding data beans into the incomplete for real-world data simulation by introducing missing values with different missingness patterns, including MCAR (complete at random), MAR (at random), MNAR (not at random), sub sequence missing, and block missing

البيانات والتحليلات

كيف تُقاس هذه الأرقام

ما يمكنك فعله

  • Classical missingness mechanisms: Simulate missing completely at random (MCAR), missing at random (MAR), and missing not at random (MNAR).
  • Time-structured corruption: Create randomly dropped observations, sequential missing segments, and block-wise missingness for time-series experiments.
  • NumPy and PyTorch support: Core corruption APIs accept NumPy arrays or PyTorch tensors and represent missing values with NaN.
  • Missingness utilities: Calculate missing rates, apply masks, and fill values while retaining observation masks for downstream learning.

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
جارٍ جمع السجل
خلال 15 يومًا
جارٍ جمع السجل
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

PyGrinder PyGrinder logo

A Python Toolkit for Simulating Missing Values in Real-World Data

Python version the latest release version Docs building PyPI downloads Conda downloads BSD-3 license Community GitHub Repo stars GitHub Repo forks GitHub contributors GitHub Testing Coveralls coverage maintainability Code Style arXiv DOI

PyGrinder is an open-source Python toolkit for simulating missing values and manipulating partially observed data. It is the missingness-simulation layer of the PyPOTS ecosystem, separated from PyPOTS so data corruption and benchmarking utilities can be used independently of model implementations.

PyGrinder implements common statistical missingness mechanisms—including MCAR, MAR, and several MNAR patterns—together with time-structured corruption strategies such as randomly dropped observations, sequential missingness, and block missingness. Core corruption functions support both NumPy arrays and PyTorch tensors.

Website · Documentation · Tutorials · Community

Key Features · Installation · Usage · Missingness Patterns · PyPOTS Ecosystem · Citing PyGrinder/PyPOTS · Contribution

❖ Key Features

  • Classical missingness mechanisms: Simulate missing completely at random (MCAR), missing at random (MAR), and missing not at random (MNAR).
  • Time-structured corruption: Create randomly dropped observations, sequential missing segments, and block-wise missingness for time-series experiments.
  • NumPy and PyTorch support: Core corruption APIs accept NumPy arrays or PyTorch tensors and represent missing values with NaN.
  • Missingness utilities: Calculate missing rates, apply masks, and fill values while retaining observation masks for downstream learning.
  • Lightweight and reusable: Use PyGrinder independently for simulation studies or together with BenchPOTS and PyPOTS for reproducible time-series experiments.
  • Research-oriented APIs: Simple functional interfaces make missingness generation easy to reproduce, inspect, and combine with custom evaluation pipelines.

❖ Installation

PyGrinder requires Python 3.10 or later and is available on PyPI and Anaconda.

Choose one of the following installation methods.

Option 1: pip (recommended)

pip install pygrinder
# To upgrade: pip install pygrinder --upgrade

Option 2: Conda

conda install conda-forge::pygrinder
# To upgrade: conda update conda-forge::pygrinder

Option 3: Latest source code on main (may include unreleased changes)

pip install https://github.com/WenjieDu/PyGrinder/archive/main.zip

❖ Usage

Quick Start

The example below generates a complete synthetic time series and introduces 10% MCAR missingness.

import numpy as np

from pygrinder import calc_missing_rate, mcar

rng = np.random.default_rng(42)
X = rng.normal(size=(128, 24, 8)).astype(np.float32)

X_missing = mcar(X, p=0.1)

print(X_missing.shape)              # (128, 24, 8)
print(calc_missing_rate(X_missing)) # approximately 0.10

PyGrinder also works directly with PyTorch tensors:

import torch

from pygrinder import seq_missing

X = torch.randn(32, 24, 8)
X_missing = seq_missing(X, p=0.1, seq_len=4)

Mask and Fill Utilities

For workflows that need both filled data and the original observation mask:

import numpy as np

from pygrinder import fill_and_get_mask

X = np.array([[1.0, np.nan], [3.0, 4.0]])
X_filled, missing_mask = fill_and_get_mask(X, 0.0)

See the PyGrinder API documentation for function signatures and parameter details.

❖ Missingness Patterns

Pattern API Description
MCAR mcar Randomly mask observations independently of the data values
MCAR diagnostic mcar_little_test Perform Little's test for evaluating an MCAR assumption
MAR mar_logistic Generate missingness through a logistic MAR mechanism
MNAR-X mnar_x Generate value-dependent MNAR missingness
MNAR-T mnar_t Generate time-dependent MNAR missingness
Non-uniform MNAR mnar_nonuniform Apply feature-dependent non-uniform replacement probabilities
Randomly dropped observations rdo Randomly remove a proportion of observed values
Sequential missingness seq_missing Mask contiguous sequences along the time dimension
Block missingness block_missing Mask contiguous time-feature blocks

Utility APIs include calc_missing_rate, masked_fill, fill_and_get_mask, fill_and_get_mask_numpy, and fill_and_get_mask_torch.

❖ PyPOTS Ecosystem

Welcome to the PyPOTS coffee universe! Each library plays a distinct role in the time-series analysis pipeline.

  • TSDB makes public time-series datasets easy to discover, download, and load.
  • PyGrinder simulates missingness and creates partially observed data for controlled experiments.
  • BenchPOTS provides standardized preprocessing pipelines for reproducible benchmarking.
  • PyPOTS provides unified modeling for imputation, forecasting, classification, clustering, anomaly detection, and representation learning.
  • BrewPOTS provides tutorials and notebooks for learning the ecosystem.

PyPOTS ecosystem pipeline
☕️ Welcome to the universe of PyPOTS. Enjoy it and have fun!

❖ Citing PyGrinder/PyPOTS

PyGrinder is developed as part of the PyPOTS ecosystem. If it supports your research, please cite the PyPOTS toolkit paper.

@article{du2023pypots,
title = {{PyPOTS: A Python Toolkit for Data Mining on Partially-Observed Time Series}},
author = {Wenjie Du},
journal = {SIGKDD MiLeTS Workshop},
url = {https://arxiv.org/abs/2305.18811v1},
year = {2023},
}
@article{du2025pypots,
title = {{PyPOTS: A Python Toolkit for Machine Learning on Partially-Observed Time Series}},
author = {Wenjie Du and Yiyuan Yang and Linglong Qian and Jun Wang and Qingsong Wen},
journal = {arXiv preprint arXiv:2305.18811v2},
url = {https://arxiv.org/abs/2305.18811v2},
year = {2025},
}

❖ Contribution

We welcome bug fixes, new missingness mechanisms, documentation improvements, and regression tests. Report reproducible problems or propose improvements through GitHub Issues.

Before submitting a pull request, enable pre-commit in your local clone:

pip install pre-commit
pre-commit install
pre-commit run --all-files

GitHub CI checks Ruff linting and formatting, package construction, dependency changes, and the supported Python matrix. If you find PyGrinder useful, consider starring the repository to help others discover it.

❖ Community

Join the PyPOTS community for questions, research discussion, feedback, and ecosystem development. You can also open a PyGrinder issue for reproducible bugs or feature requests.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…