dataspecs

Data specifications by data classes

https://github.com/astropenguin/dataspecs

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.5%) to scientific vocabulary

Keywords

dataclasses python specifications typing
Last synced: 6 months ago · JSON representation ·

Repository

Data specifications by data classes

Basic Info
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 17
Topics
dataclasses python specifications typing
Created over 2 years ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

dataspecs

Release Python Downloads DOI Tests

Data specifications by data classes

Installation

shell pip install dataspecs

Basic usage

Common imports and tags

```python from dataclasses import dataclass from dataspecs import TagBase, from_dataclass from enum import auto from typing import Annotated as Ann

class Tag(TagBase): ATTR = auto() DATA = auto() DTYPE = auto() ```

Simple specifications

```python @dataclass class Weather: temp: list[float] humid: list[float] location: str

specs = from_dataclass(Weather([20.0, 25.0], [50.0, 55.0], "Tokyo")) print(specs) Specs([ Spec(path=Path('/temp'), name='temp', tags=(), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/temp/0'), name='0', tags=(), type=, data=None), Spec(path=Path('/humid'), name='humid', tags=(), type=list[float], data=[50.0, 55.0]), Spec(path=Path('/humid/0'), name='0', tags=(), type=, data=None), Spec(path=Path('/location'), name='location', tags=(), type=, data='Tokyo'), ]) ```

Simple specifications with tags

```python @dataclass class Weather: temp: Ann[list[float], Tag.DATA] humid: Ann[list[float], Tag.DATA] location: str

specs = from_dataclass(Weather([20.0, 25.0], [50.0, 55.0], "Tokyo")) print(specs) Specs([ Spec(path=Path('/temp'), name='temp', tags=(,), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/temp/0'), name='0', tags=(), type=, data=None), Spec(path=Path('/humid'), name='humid', tags=(,), type=list[float], data=[50.0, 55.0]), Spec(path=Path('/humid/0'), name='0', tags=(), type=, data=None), Spec(path=Path('/location'), name='location', tags=(), type=, data='Tokyo'), ]) ```

Nested specifications (with tags)

```python @dataclass class Meta: units: Ann[str, Tag.ATTR]

@dataclass class Weather: temp: Ann[list[Ann[float, Tag.DTYPE]], Tag.DATA, Meta("degC")] humid: Ann[list[Ann[float, Tag.DTYPE]], Tag.DATA, Meta("%")] location: str

specs = from_dataclass(Weather([20.0, 25.0], [50.0, 55.0], "Tokyo")) print(specs) Specs([ Spec(path=Path('/temp'), name='temp', tags=(,), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/temp/0'), name='0', tags=(,), type=, data=None), Spec(path=Path('/temp/units'), name='units', tags=(,), type=, data='degC'), Spec(path=Path('/humid'), name='humid', tags=(,), type=list[float], data=[50.0, 55.0]), Spec(path=Path('/humid/0'), name='0', tags=(,), type=, data=None), Spec(path=Path('/humid/units'), name='units', tags=(,), type=, data='%'), Spec(path=Path('/location'), name='location', tags=(), type=, data='Tokyo'), ]) ```

Selecting specifications

python specs[Tag.DATA] Specs([ Spec(path=Path('/temp'), name='temp', tags=(<Tag.DATA: 2>,), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/humid'), name='humid', tags=(<Tag.DATA: 2>,), type=list[float], data=[50.0, 55.0]), ])

python specs[Tag] Specs([ Spec(path=Path('/temp'), name='temp', tags=(<Tag.DATA: 2>,), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/temp/0'), name='0', tags=(<Tag.DTYPE: 3>,), type=<class 'float'>, data=None), Spec(path=Path('/temp/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='degC'), Spec(path=Path('/humid'), name='humid', tags=(<Tag.DATA: 2>,), type=list[float], data=[50.0, 55.0]), Spec(path=Path('/humid/0'), name='0', tags=(<Tag.DTYPE: 3>,), type=<class 'float'>, data=None), Spec(path=Path('/humid/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='%'), ])

python specs[str] Specs([ Spec(path=Path('/temp/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='degC'), Spec(path=Path('/humid/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='%'), Spec(path=Path('/location'), name='location', tags=(), type=<class 'str'>, data='Tokyo'), ])

python specs["/temp/[a-z]+"] Specs([ Spec(path=Path('/temp/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='degC'), ])

Grouping specifications

python specs.groupby("tags") [ Specs([ Spec(path=Path('/temp'), name='temp', tags=(<Tag.DATA: 2>,), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/humid'), name='humid', tags=(<Tag.DATA: 2>,), type=list[float], data=[50.0, 55.0]), ]), Specs([ Spec(path=Path('/temp/0'), name='0', tags=(<Tag.DTYPE: 3>,), type=<class 'float'>, data=None), Spec(path=Path('/humid/0'), name='0', tags=(<Tag.DTYPE: 3>,), type=<class 'float'>, data=None), ]), Specs([ Spec(path=Path('/temp/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='degC'), Spec(path=Path('/humid/units'), name='units', tags=(<Tag.ATTR: 1>,), type=<class 'str'>, data='%'), ]), Specs([ Spec(path=Path('/location'), name='location', tags=(), type=<class 'str'>, data='Tokyo'), ]), ]

Advanced usage

Formatting specifications

```python from dataspecs import Format, format

@dataclass class Meta: units: Ann[str, Tag.ATTR]

@dataclass class Weather: temp: Ann[float, Meta("{0}")] humid: Ann[float, Meta("{0}")] tempunits: Ann[str, Format("/temp/units")] humidunits: Ann[str, Format("/humid/units")]

format(fromdataclass(Weather(20.0, 50.0, "degC", "%"))) Specs([ Spec(path=Path('/temp'), name='temp', tags=(), type=, data=20.0), Spec(path=Path('/temp/units'), name='units', tags=(,), type=, data='degC'), # <- data formatted Spec(path=Path('/humid'), name='humid', tags=(), type=, data=50.0), Spec(path=Path('/humid/units'), name='units', tags=(,), type=, data='%'), # <- data formatted Spec(path=Path('/tempunits'), name='tempunits', tags=(), type=, data='degC'), Spec(path=Path('/humidunits'), name='humid_units', tags=(), type=, data='%'), ]) ```

Naming specifications

```python from dataspecs import Name, name

@dataclass class Weather: temp: Ann[float, Name("Ground temperature")] humid: Ann[float, Name("Relative humidity")]

name(from_dataclass(Weather(20.0, 50.0))) Specs([ Spec(path=Path('/temp'), name='Ground temperature', tags=(), type=, data=20.0), # <- name replaced Spec(path=Path('/humid'), name='Relative humidity', tags=(), type=, data=50.0), # <- name replaced ]) ```

Replacing specifications

```python from dataspecs import Replace, replace

@dataclass class Weather: temp: Ann[list[Ann[float, Tag.DTYPE]], Tag.DATA] humid: Ann[list[Ann[float, Tag.DTYPE]], Tag.DATA] dtype: Ann[type, Replace("/[a-z]+/0", "type")]

replace(from_dataclass(Weather([20.0, 25.0], [50.0, 55.0], int))) Specs([ Spec(path=Path('/temp'), name='temp', tags=(,), type=list[float], data=[20.0, 25.0]), Spec(path=Path('/temp/0'), name='0', tags=(,), type=, data=None), # <- type replaced Spec(path=Path('/humid'), name='humid', tags=(,), type=list[float], data=[50.0, 55.0]), Spec(path=Path('/humid/0'), name='0', tags=(,), type=, data=None), # <- type replaced Spec(path=Path('/dtype'), name='dtype', tags=(), type=, data=), ]) ```

Specification rules

First union type as representative type

```python @dataclass class Weather: temp: list[int | float] | (int | float)

from_dataclass(Weather(0.0)) Specs([ Spec(path=Path('/temp'), name='temp', tags=(), type=list[int | float], data=0.0), Spec(path=Path('/temp/0'), name='0', tags=(), type=, data=None), ]) ```

Owner

  • Name: Akio Taniguchi
  • Login: astropenguin
  • Kind: user
  • Location: Nagoya, Japan
  • Company: Nagoya University

Project assistant professor (LMT-FINER)

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: dataspecs
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Akio
    family-names: Taniguchi
    email: taniguchi.akio@gmail.com
    affiliation: Kitami Institute of Technology
    orcid: 'https://orcid.org/0000-0002-9695-6183'
identifiers:
  - type: doi
    value: 10.5281/zenodo.10652375
repository-code: 'https://github.com/astropenguin/dataspecs'
url: 'https://astropenguin.github.io/dataspecs/v5.0.0'
abstract: Data specifications by data classes
keywords:
  - python
  - dataclasses
  - specifications
  - typing
license: MIT
version: 5.0.0
date-released: '2025-01-14'

GitHub Events

Total
  • Create event: 25
  • Release event: 8
  • Issues event: 43
  • Watch event: 2
  • Delete event: 18
  • Push event: 74
  • Pull request event: 39
Last Year
  • Create event: 25
  • Release event: 8
  • Issues event: 43
  • Watch event: 2
  • Delete event: 18
  • Push event: 74
  • Pull request event: 39

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 53
  • Total pull requests: 61
  • Average time to close issues: 24 days
  • Average time to close pull requests: 3 days
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 54
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 23
  • Pull requests: 37
  • Average time to close issues: 12 days
  • Average time to close pull requests: 1 day
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 31
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • astropenguin (54)
Pull Request Authors
  • astropenguin (87)
Top Labels
Issue Labels
feature (40) release (13) bug (7) docs (4) env (2)
Pull Request Labels
feature (60) release (24) bug (15) env (4) docs (4)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 128 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 17
  • Total maintainers: 1
pypi.org: dataspecs

Data specifications by data classes

  • Documentation: https://dataspecs.readthedocs.io/
  • License: MIT License Copyright (c) 2023-2025 Akio Taniguchi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 5.0.0
    published about 1 year ago
  • Versions: 17
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 128 Last month
Rankings
Dependent packages count: 7.4%
Average: 38.1%
Dependent repos count: 68.9%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/pypi.yaml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/tests.yaml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
poetry.lock pypi
  • black 23.9.1
  • click 8.1.7
  • colorama 0.4.6
  • exceptiongroup 1.1.3
  • iniconfig 2.0.0
  • mypy 1.5.1
  • mypy-extensions 1.0.0
  • nodeenv 1.8.0
  • packaging 23.1
  • pathspec 0.11.2
  • platformdirs 3.10.0
  • pluggy 1.3.0
  • pyright 1.1.327
  • pytest 7.4.2
  • setuptools 68.2.2
  • tomli 2.0.1
  • typing-extensions 4.8.0
pyproject.toml pypi
  • python ^3.9
.github/workflows/gh-pages.yaml actions
  • abatilo/actions-poetry v2 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • peaceiris/actions-gh-pages v3 composite