Registry / data / tabmat

tabmat

JSON →
library4.2.1pypypi✓ verified 85d ago

Tabmat provides efficient matrix representations for working with tabular data, designed to integrate seamlessly with various dataframe libraries. It offers specialized matrix types like DenseMatrix, CategoricalMatrix, and SplitMatrix for performance-critical statistical and machine learning tasks, especially useful for generalized linear models. The current version is 4.2.1, with an active development pace and frequent releases addressing bug fixes and new features.

pip install tabmat
INSTALL
IMPORT
SIG · TABMAT
T
tabmat
datapythonv4.2.1
Install
12.7s avg
Import
1897ms
Disk
332MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.2.1 · 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.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 12.7s · import 1.897s · 326MB
332MB installed
● package 332MB
Code
Verified usage

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

from_df
from tabmat import from_df
from_formula
from tabmat import from_formula
DenseMatrix
from tabmat import DenseMatrix
import tabmat.DenseMatrix
Class is directly in the tabmat package, not a submodule.
CategoricalMatrix
from tabmat import CategoricalMatrix
SplitMatrix
from tabmat import SplitMatrix

This quickstart demonstrates how to create a `SplitMatrix` from a pandas DataFrame using `tabmat.from_df`. It automatically handles different column types, applying standardization and one-hot encoding as specified. The example then shows how to perform a matrix-vector multiplication, a common operation for `tabmat` objects.

import pandas as pd import tabmat as tm import numpy as np # Create a sample DataFrame df = pd.DataFrame({"numeric_col": [1, 2, 3, 4], "categorical_col": ["A", "B", "A", "C"], "bool_col": [True, False, True, False]}) # Create a SplitMatrix from the DataFrame, standardizing numeric columns # and dropping the first level for categorical encoding matrix = tm.from_df(df, standardize=True, drop_first=True) print(f"Matrix shape: {matrix.shape}") print(f"Matrix parts (e.g., DenseMatrix, CategoricalMatrix): {matrix.matrices}") # Example of matrix-vector multiplication vec = np.random.rand(matrix.shape[1]) result = matrix.matvec(vec) print(f"Result of matvec (first 5 elements): {result[:5]}")
Debug
Known issues
breakingAs of v4.0.0, `DenseMatrix` and `SparseMatrix` no longer inherit from `numpy.ndarray` and `scipy.sparse.csc_matrix` respectively. Direct array-like access (e.g., `.A`) or implicit conversion will now fail.
fix
Use the `.unpack()` method (or `.toarray()` for `DenseMatrix`) to explicitly convert to the underlying array type before performing operations that require a standard NumPy array or SciPy sparse matrix. For example, `dense_matrix.unpack()`.
affects: >=4.0.0
breakingTabmat v4.2.0 and later require Python 3.10 or newer. Installation via `pip` will fail with an incompatibility error on older Python versions.
fix
Upgrade your Python environment to version 3.10 or higher. If unable to upgrade, install an older version of tabmat, e.g., `pip install "tabmat<4.2.0"`.
affects: >=4.2.0
gotchaMethods of `CategoricalMatrix` and related internal functions in versions prior to 4.2.1/4.1.3 might raise a `RuntimeError` when operating on read-only buffers (e.g., NumPy arrays with `writeable=False`).
fix
Upgrade to tabmat >=4.2.1, which includes fixes for read-only buffer handling across various matrix operations. If upgrading is not an option, ensure that any input arrays passed to tabmat methods are writable (e.g., by making a copy: `my_array.copy()`).
affects: <4.2.1
gotcha`tabmat.from_df` and `tabmat.from_formula` now use `narwhals`' v2 API and support a wider range of dataframes (including `polars`). While this enhances compatibility, users should be aware of potential subtle behavioral changes if they were relying on specific `pandas` dataframe quirks or older `narwhals` API behavior.
fix
Test your existing code with the new versions. Consult the `narwhals` documentation if you encounter unexpected behavior, especially when working with non-pandas dataframes or specific dataframe operations.
affects: >=4.1.4
Errors
Common errors & fixes
AttributeError: 'DenseMatrix' object has no attribute 'A'
Attempting to access the underlying NumPy array using the `.A` attribute, which was removed in tabmat v4.0.0 when `DenseMatrix` stopped inheriting from `np.ndarray`.
fix
Use `dense_matrix.unpack()` or `dense_matrix.toarray()` to get the underlying NumPy array for direct array manipulation.
TypeError: can't convert DenseMatrix to numpy.ndarray implicitly
Trying to pass a `DenseMatrix` directly where a `numpy.ndarray` is expected, due to the breaking change in tabmat v4.0.0 that removed direct inheritance from `np.ndarray`.
fix
Explicitly convert the `DenseMatrix` to a NumPy array using `dense_matrix.unpack()` or `dense_matrix.toarray()` before passing it to functions expecting a `np.ndarray`.
ERROR: Package 'tabmat' requires Python '>=3.10' but the running Python is 3.X.Y
Attempting to install or use tabmat version 4.2.0 or higher with an incompatible Python version (older than 3.10).
fix
Upgrade your Python environment to 3.10 or newer. If an upgrade is not possible, install an older version of tabmat: `pip install "tabmat<4.2.0"`.
RuntimeError: buffer source array is read-only
Certain `CategoricalMatrix` methods or related internal operations in older tabmat versions were called with an immutable (read-only) NumPy array or buffer, which they attempted to modify.
fix
Upgrade to tabmat version 4.2.1 or newer, which includes fixes for operating on read-only buffers. If an upgrade is not possible, ensure any input arrays are writable, e.g., by creating a copy: `my_array.copy(order='C')`.
Upgrade
Version history
4.2.1latest on PyPI · released Feb 4, 2026
Audit
Dependencies
numpyrequiredCore numerical operations and array representations.
scipyrequiredUsed for sparse matrix operations and components like `sps.csc_matrix`.
pandasoptionalCommonly used for input dataframes, especially with `from_df` and `from_formula`.
narwhalsoptionalEnables support for various dataframe types (e.g., Polars, PyArrow) via `from_df` and `from_formula`.
Agent activity
35 hits · last 30 days
node
32
Bingbot
1
OpenAI (training)
1
Resources
tabmat — pip install tabmat · libregistry