Skip to main content

Arrow-backed DataFrames with native tensor column support for PyTorch/JAX

Project description

TensorFrame

Arrow-backed DataFrames with native tensor column support for PyTorch/JAX.

TensorFrame bridges the gap between tabular data processing (Pandas/Polars) and deep learning tensor execution (PyTorch/JAX) — without falling back to slow Python object arrays.

Install

pip install tensorframe

Quick Start

import tensorframe as tf
import numpy as np
import pandas as pd

# Create a DataFrame with a 1024-D embedding column
embeddings = np.random.randn(1000, 1024).astype("float32")
df = pd.DataFrame({
    "patient_id": range(1000),
    "age":        np.random.randint(20, 80, 1000).astype(float),
    "features":   pd.Series(tf.TensorArray(embeddings)),
})

# L2-normalise directly on the column
df["norm"] = df["features"].tensor.l2_normalize()

# Filter rows by cosine similarity to a query vector
target = np.random.randn(1024).astype("float32")
scores  = df["norm"].tensor.dot(target)
filtered = df[scores > 0.5]

# Zero-friction PyTorch DataLoader
loader = tf.to_pytorch_dataloader(
    filtered,
    features=["norm", "age"],
    targets="patient_id",
    batch_size=64,
    shuffle=True,
)
for batch in loader:
    x = batch["norm"]      # torch.Tensor (64, 1024)
    y = batch["target"]    # torch.Tensor (64,)

Read Parquet (auto-detects tensor columns)

df = tf.read_parquet("multimodal_biomarkers.parquet")
# Any FixedSizeList columns are automatically wrapped as TensorArray

Key Features

Feature Details
Arrow-backed storage FixedSizeList — one contiguous C memory block per column
Zero-copy to numpy np.frombuffer wraps the Arrow buffer — no allocation
Efficient PyTorch bridge Single memcpy from Arrow → writeable numpy → torch.from_numpy
.tensor accessor l2_normalize, dot, cosine_similarity, mean, norm, reshape
Parquet round-trip Tensor shape metadata preserved through write/read cycles
NIfTI support tf.read_nifti_batch(paths) for volumetric medical imaging
Out-of-core iteration tf.iter_chunks, ChunkedDataLoader for large datasets

Requirements

  • Python ≥ 3.9
  • numpy, pandas, pyarrow
  • Optional: torch (for GPU ops and DataLoader), nibabel (NIfTI I/O)

Author

Md. Shahinur Hasanshahinhasanronys@gmail.com

GitHub: https://github.com/Shahinurhasans/TensorFrame

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensorframe-0.1.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensorframe-0.1.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file tensorframe-0.1.0.tar.gz.

File metadata

  • Download URL: tensorframe-0.1.0.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for tensorframe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c0233ec30d173cbe39c7a0497fe649b1c6aabff9c8ea32cd0d7dd8f3512d12b
MD5 591ab339f5eb4d403b5569844030d9db
BLAKE2b-256 ecd9a373cb20db66d5f9b2a78a2d33a1932c332de84b11586d9226452ce64546

See more details on using hashes here.

File details

Details for the file tensorframe-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tensorframe-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for tensorframe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfe2c2b1d31abfb0b91253c82fa06097864382c2982e78ccd34e5011ecd2f5db
MD5 df9352f3f16970efcf674df5551dbb8e
BLAKE2b-256 8950f2c189c944568e0e3bd4f542bd74818dc1c5e94d8dbe59c5b14d998c3cc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page