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.6.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.6-py3-none-any.whl (8.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_types-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 a0bc0f555ab3c579462e464b7914a925e539616bcf8649adf45677f955a0760d
MD5 2ef8d994310348a8e86d50d5c9a8c4f8
BLAKE2b-256 17dfaf3497deb437ea39709304020fa9998b8fc90f06717353690a62ca1efcf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_types-0.1.6.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.6-py3-none-any.whl.

File metadata

  • Download URL: scitex_types-0.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 635e2a853cd9d76da77454e3a49e33796f0612b3cf1cb53317168455ba2bc0a5
MD5 212e7fc39536dba99580a51a541c3b4f
BLAKE2b-256 2638cf109ee65b24b1be425e91fe4bd23f66d4fc5e7b0202c35f62134b14e227

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_types-0.1.6-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