Registry / data / patsy

patsy

JSON →
library1.0.2pypypi✓ verified 35d ago

Patsy is a Python package for describing statistical models and for building design matrices, bringing R-style formulas to Python. The current version is 1.0.2. While no new feature development is planned, it maintains a maintenance cadence to ensure compatibility with current releases in the Python ecosystem.

data
Install & Compatibility
Where this runs
tested against v1.0.2 · 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
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.274s · 90.8MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 3.7s · import 0.271s · 87MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from patsy import dmatrix
from patsy import dmatrices

A utility function for quick examples and testing.

from patsy import demo_data

This quickstart demonstrates how to use `patsy.dmatrices` to generate design matrices from a formula string and a dictionary-like data source. It automatically handles categorical variables and adds an intercept term.

import numpy as np from patsy import dmatrices, demo_data # Create example data data = demo_data("a", "b", "x1", "x2", "y") # Generate design matrices for a linear model y, X = dmatrices("y ~ x1 + x2 + a", data=data) print("Dependent variable (y):") print(y) print("\nIndependent variables (X):") print(X)
Debug
Known footguns
breakingPython 2.7 support was dropped in version 1.0.0. Projects still on Python 2 must use an older version of Patsy.
gotchaPatsy automatically adds an intercept term and uses treatment coding for categorical variables (dropping one level). If you need to include all levels or omit the intercept, adjust your formula accordingly (e.g., `y ~ x1 + C(a) - 1` to remove intercept and explicitly code `a`).
gotchaThe `NA_action='drop'` is the default for `dmatrix` and `dmatrices`, which means rows containing any missing values will be silently dropped. This can lead to unexpected data loss if not anticipated.
gotchaOperators like `**` in Patsy formulas are interpreted as interaction effects, not Python's power operator. Use `I()` (identity function) to force Python's interpretation (e.g., `I(x**2)`).
gotchaPatsy fixed compatibility issues with `numpy >= 2` in version 1.0.0. Older versions might not work correctly with newer NumPy.
gotchaPatsy fixed compatibility with Pandas 3's new `StringDtype` in version 1.0.2. Older versions may encounter issues with Pandas 3.
deprecatedThe project is explicitly stated as 'no longer under active development' for new features, with 'Formulaic' identified as its spiritual successor. For new projects, considering Formulaic might be beneficial.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
12 hits · last 30 days
gptbot
4
claudebot
4
ahrefsbot
3
Resources