Skip to main content

Scientific type definitions (ArrayLike, ColorLike) and validation

Project description

scitex-types

SciTeX

Scientific type aliases (ArrayLike, ColorLike) + runtime validation predicates.

Full Documentation · uv pip install scitex-types[all]

pypi python docs

tests cov


Problem and Solution

# Problem Solution
1 numpy.typing.ArrayLike covers only NumPy — functions that also accept Torch/DataFrame/Series need a hand-rolled Union ArrayLike, ColorLike — stable aliases spanning list/tuple/np.ndarray/pd.DataFrame/pd.Series/xr.DataArray/torch.Tensor + matplotlib color inputs
2 Runtime "is this a list of floats?" is a 3-line comprehension is_array_like(), is_list_of_type(lst, float) — clear predicates, no isinstance chain

Architecture

scitex_types/
├── _aliases.py     # ArrayLike, ColorLike unions
└── _predicates.py  # is_array_like, is_list_of_type
flowchart LR
    A[list / tuple] --> AL[ArrayLike]
    B[np.ndarray] --> AL
    C[pd.DataFrame / Series] --> AL
    D[xr.DataArray] --> AL
    E[torch.Tensor] --> AL
    AL --> P[is_array_like]
    F[mpl color string / RGB / RGBA] --> CL[ColorLike]
    style AL fill:#4a90d9,stroke:#2c3e50,color:#fff
    style CL fill:#8e44ad,stroke:#2c3e50,color:#fff

Figure 1. Type surface. Two aliases unify common scientific containers and matplotlib color inputs; predicates resolve membership at runtime.

Installation

pip install scitex-types
# Optional: enable array-library matches (numpy + pandas + torch + xarray):
pip install scitex-types[all]

Quick Start

from scitex_types import ArrayLike, is_array_like, is_list_of_type

def process(data: ArrayLike) -> None: ...

is_array_like([1, 2, 3])           # True
is_list_of_type([1, 2, 3], int)    # True

1 Interfaces

Python API
from scitex_types import ArrayLike, ColorLike, is_array_like, is_list_of_type

# Type annotations
def process(data: ArrayLike) -> None: ...
def set_color(c: ColorLike) -> None: ...

# Runtime checks
is_array_like([1, 2, 3])           # True
is_array_like("not array")         # False
is_list_of_type([1, 2, 3], int)    # True
is_list_of_type([1, "x"], int)     # False

Demo

from scitex_types import ArrayLike, is_array_like, is_list_of_type

def normalize(x: ArrayLike) -> ArrayLike:
    assert is_array_like(x)
    return x

normalize([1, 2, 3])             # OK
normalize("not array")           # AssertionError

is_list_of_type([1, 2, 3], int)  # True — uniform int list
is_list_of_type([1, "x"], int)   # False — mixed
flowchart LR
    Input[Function input] --> Pred{is_array_like?}
    Pred -- yes --> Proceed[proceed]
    Pred -- no --> Raise[raise / branch]
    style Proceed fill:#27ae60,stroke:#2c3e50,color:#fff
    style Raise fill:#e74c3c,stroke:#2c3e50,color:#fff

Figure 2. Demo. Use ArrayLike in annotations, is_array_like as a one-line guard.

Part of SciTeX

scitex-types is part of SciTeX. Install via the umbrella with pip install scitex[types] to use as scitex.types (Python) or scitex types ... (CLI).

Four Freedoms for Research

  1. The freedom to run your research anywhere — your machine, your terms.
  2. The freedom to study how every step works — from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. The freedom to modify any module and share improvements with the community.

AGPL-3.0 — because we believe research infrastructure deserves the same freedoms as the software it runs on.

License

AGPL-3.0-only (see LICENSE).


SciTeX

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

scitex_types-0.1.5.tar.gz (8.6 MB view details)

Uploaded Source

Built Distribution

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

scitex_types-0.1.5-py3-none-any.whl (8.2 MB view details)

Uploaded Python 3

File details

Details for the file scitex_types-0.1.5.tar.gz.

File metadata

  • Download URL: scitex_types-0.1.5.tar.gz
  • Upload date:
  • Size: 8.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_types-0.1.5.tar.gz
Algorithm Hash digest
SHA256 09ec30d56c644e457c719661bd8026764612c5d58a4614f6dfb42aab4f1f31c9
MD5 9cc4b5f23340689910b16789c71bc2b4
BLAKE2b-256 9dfe8a08d45b64dca196b10721b22b498450749b7c77d7f2a7f2a7f662b65528

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_types-0.1.5.tar.gz:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-types

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scitex_types-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: scitex_types-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_types-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 93e3ee4ecb941c8dd25e00c0733b66ee68246ace16154c932e4205e241e5efdc
MD5 361fc30feef52f37a5fadd0c5596f999
BLAKE2b-256 a11791d6aeb8b56c1920740225057a90f44ad8c54fbb4090aaf6ffa9788689c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_types-0.1.5-py3-none-any.whl:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-types

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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