pavise 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pavise-0.0.1/.github/workflows/release.yml +35 -0
- pavise-0.0.1/.github/workflows/test.yml +81 -0
- pavise-0.0.1/.gitignore +3 -0
- pavise-0.0.1/PKG-INFO +222 -0
- pavise-0.0.1/README.md +197 -0
- pavise-0.0.1/pyproject.toml +71 -0
- pavise-0.0.1/src/pavise/__init__.py +4 -0
- pavise-0.0.1/src/pavise/_pandas/__init__.py +1 -0
- pavise-0.0.1/src/pavise/_pandas/validation.py +292 -0
- pavise-0.0.1/src/pavise/_pandas/validator_impl.py +144 -0
- pavise-0.0.1/src/pavise/_polars/__init__.py +1 -0
- pavise-0.0.1/src/pavise/_polars/validation.py +178 -0
- pavise-0.0.1/src/pavise/_polars/validator_impl.py +150 -0
- pavise-0.0.1/src/pavise/exceptions.py +63 -0
- pavise-0.0.1/src/pavise/pandas.py +54 -0
- pavise-0.0.1/src/pavise/polars.py +57 -0
- pavise-0.0.1/src/pavise/validators.py +74 -0
- pavise-0.0.1/tests/test_pandas/__init__.py +0 -0
- pavise-0.0.1/tests/test_pandas/test_dataframe.py +368 -0
- pavise-0.0.1/tests/test_pandas/test_detailed_errors.py +47 -0
- pavise-0.0.1/tests/test_pandas/test_validator_detailed_errors.py +108 -0
- pavise-0.0.1/tests/test_pandas/test_validators.py +123 -0
- pavise-0.0.1/tests/test_polars/__init__.py +0 -0
- pavise-0.0.1/tests/test_polars/test_dataframe.py +219 -0
- pavise-0.0.1/tests/test_polars/test_detailed_errors.py +58 -0
- pavise-0.0.1/tests/test_polars/test_validator_detailed_errors.py +108 -0
- pavise-0.0.1/tests/test_polars/test_validators.py +123 -0
- pavise-0.0.1/tox.ini +29 -0
- pavise-0.0.1/uv.lock +1038 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- '*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
environment:
|
|
14
|
+
name: pypi
|
|
15
|
+
url: https://pypi.org/p/pavise
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- name: Set up the latest version of uv
|
|
20
|
+
uses: astral-sh/setup-uv@v7
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
- name: Build and publish
|
|
24
|
+
run: |
|
|
25
|
+
uv build
|
|
26
|
+
uv publish
|
|
27
|
+
|
|
28
|
+
- name: upload windows dists
|
|
29
|
+
uses: actions/upload-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: release-dists
|
|
32
|
+
path: dist/
|
|
33
|
+
|
|
34
|
+
- name: Publish package distributions to PyPI
|
|
35
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test Python ${{ matrix.python-version }} - ${{ matrix.backend }}
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
17
|
+
backend: [pandas, polars, all]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: ${{ matrix.python-version }}
|
|
26
|
+
|
|
27
|
+
- name: Install uv
|
|
28
|
+
uses: astral-sh/setup-uv@v5
|
|
29
|
+
|
|
30
|
+
- name: Install tox
|
|
31
|
+
run: uv pip install --system tox tox-uv
|
|
32
|
+
|
|
33
|
+
- name: Run tests with tox
|
|
34
|
+
run: |
|
|
35
|
+
PYTHON_VERSION=$(echo "${{ matrix.python-version }}" | tr -d '.')
|
|
36
|
+
tox -e py${PYTHON_VERSION}-${{ matrix.backend }}
|
|
37
|
+
|
|
38
|
+
lint:
|
|
39
|
+
name: Lint
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v4
|
|
44
|
+
|
|
45
|
+
- name: Set up Python
|
|
46
|
+
uses: actions/setup-python@v5
|
|
47
|
+
with:
|
|
48
|
+
python-version: "3.12"
|
|
49
|
+
|
|
50
|
+
- name: Install uv
|
|
51
|
+
uses: astral-sh/setup-uv@v5
|
|
52
|
+
|
|
53
|
+
- name: Install dependencies
|
|
54
|
+
run: uv sync --all-extras
|
|
55
|
+
|
|
56
|
+
- name: Run ruff check
|
|
57
|
+
run: uv run ruff check
|
|
58
|
+
|
|
59
|
+
- name: Run ruff format check
|
|
60
|
+
run: uv run ruff format --check
|
|
61
|
+
|
|
62
|
+
type-check:
|
|
63
|
+
name: Type Check
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
|
|
66
|
+
steps:
|
|
67
|
+
- uses: actions/checkout@v4
|
|
68
|
+
|
|
69
|
+
- name: Set up Python
|
|
70
|
+
uses: actions/setup-python@v5
|
|
71
|
+
with:
|
|
72
|
+
python-version: "3.12"
|
|
73
|
+
|
|
74
|
+
- name: Install uv
|
|
75
|
+
uses: astral-sh/setup-uv@v5
|
|
76
|
+
|
|
77
|
+
- name: Install dependencies
|
|
78
|
+
run: uv sync --all-extras
|
|
79
|
+
|
|
80
|
+
- name: Run type check
|
|
81
|
+
run: uv run pyrefly check
|
pavise-0.0.1/.gitignore
ADDED
pavise-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pavise
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: DataFrame validation library using Python Protocol for structural subtyping
|
|
5
|
+
Author: kitagry
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
9
|
+
Provides-Extra: all
|
|
10
|
+
Requires-Dist: pandas>=1.3.0; extra == 'all'
|
|
11
|
+
Requires-Dist: polars>=0.15.0; extra == 'all'
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pandas>=1.3.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: polars>=0.15.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: pyrefly>=0.1.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: tox>=4.0.0; extra == 'dev'
|
|
20
|
+
Provides-Extra: pandas
|
|
21
|
+
Requires-Dist: pandas>=1.3.0; extra == 'pandas'
|
|
22
|
+
Provides-Extra: polars
|
|
23
|
+
Requires-Dist: polars>=0.15.0; extra == 'polars'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# Pavise
|
|
27
|
+
|
|
28
|
+
DataFrame validation library using Python Protocol for structural subtyping.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Use Python Protocol to define DataFrame schemas
|
|
33
|
+
- `DataFrame[Schema]` type annotation for static type checking
|
|
34
|
+
- Structural subtyping: validate only required columns, ignore extra columns
|
|
35
|
+
- Covariant type parameters: `DataFrame[ChildSchema]` is compatible with `DataFrame[ParentSchema]`
|
|
36
|
+
- Optional runtime validation
|
|
37
|
+
- No inheritance required
|
|
38
|
+
- Support for both pandas and polars backends
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# For pandas support
|
|
44
|
+
pip install pavise[pandas]
|
|
45
|
+
|
|
46
|
+
# For polars support
|
|
47
|
+
pip install pavise[polars]
|
|
48
|
+
|
|
49
|
+
# For both
|
|
50
|
+
pip install pavise[all]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
### Pandas Backend
|
|
56
|
+
|
|
57
|
+
#### Static Type Checking Only (Recommended)
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from typing import Protocol
|
|
61
|
+
from pavise.pandas import DataFrame
|
|
62
|
+
|
|
63
|
+
class UserSchema(Protocol):
|
|
64
|
+
name: str
|
|
65
|
+
age: int
|
|
66
|
+
|
|
67
|
+
def process_users(df: DataFrame[UserSchema]) -> DataFrame[UserSchema]:
|
|
68
|
+
# mypy/pyrefly will check types, no runtime validation
|
|
69
|
+
return df[df['age'] >= 18]
|
|
70
|
+
|
|
71
|
+
# Use regular pandas DataFrame
|
|
72
|
+
import pandas as pd
|
|
73
|
+
df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
74
|
+
result = process_users(df)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Runtime Validation (Explicit)
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from typing import Protocol
|
|
81
|
+
import pandas as pd
|
|
82
|
+
from pavise.pandas import DataFrame
|
|
83
|
+
|
|
84
|
+
class UserSchema(Protocol):
|
|
85
|
+
name: str
|
|
86
|
+
age: int
|
|
87
|
+
|
|
88
|
+
def load_users(raw_df: pd.DataFrame) -> DataFrame[UserSchema]:
|
|
89
|
+
# Validate at runtime when needed
|
|
90
|
+
return DataFrame[UserSchema](raw_df)
|
|
91
|
+
|
|
92
|
+
raw_df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
93
|
+
validated_df = load_users(raw_df) # Runtime validation occurs here
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Polars Backend
|
|
97
|
+
|
|
98
|
+
#### Static Type Checking Only (Recommended)
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from typing import Protocol
|
|
102
|
+
from pavise.polars import DataFrame
|
|
103
|
+
|
|
104
|
+
class UserSchema(Protocol):
|
|
105
|
+
name: str
|
|
106
|
+
age: int
|
|
107
|
+
|
|
108
|
+
def process_users(df: DataFrame[UserSchema]) -> DataFrame[UserSchema]:
|
|
109
|
+
# mypy/pyrefly will check types, no runtime validation
|
|
110
|
+
return df.filter(df['age'] >= 18)
|
|
111
|
+
|
|
112
|
+
# Use regular polars DataFrame
|
|
113
|
+
import polars as pl
|
|
114
|
+
df = pl.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
115
|
+
result = process_users(df)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Runtime Validation (Explicit)
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from typing import Protocol
|
|
122
|
+
import polars as pl
|
|
123
|
+
from pavise.polars import DataFrame
|
|
124
|
+
|
|
125
|
+
class UserSchema(Protocol):
|
|
126
|
+
name: str
|
|
127
|
+
age: int
|
|
128
|
+
|
|
129
|
+
def load_users(raw_df: pl.DataFrame) -> DataFrame[UserSchema]:
|
|
130
|
+
# Validate at runtime when needed
|
|
131
|
+
return DataFrame[UserSchema](raw_df)
|
|
132
|
+
|
|
133
|
+
raw_df = pl.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
134
|
+
validated_df = load_users(raw_df) # Runtime validation occurs here
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Structural Subtyping
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from typing import Protocol
|
|
141
|
+
import pandas as pd
|
|
142
|
+
from pavise.pandas import DataFrame
|
|
143
|
+
|
|
144
|
+
class UserSchema(Protocol):
|
|
145
|
+
name: str
|
|
146
|
+
|
|
147
|
+
class UserWithEmailSchema(Protocol):
|
|
148
|
+
name: str
|
|
149
|
+
email: str
|
|
150
|
+
|
|
151
|
+
def process_user(df: DataFrame[UserSchema]) -> None:
|
|
152
|
+
print(df['name'])
|
|
153
|
+
|
|
154
|
+
# This works! UserWithEmailSchema has all required columns of UserSchema
|
|
155
|
+
df: DataFrame[UserWithEmailSchema] = pd.DataFrame({
|
|
156
|
+
'name': ['Alice'],
|
|
157
|
+
'email': ['alice@example.com']
|
|
158
|
+
})
|
|
159
|
+
process_user(df) # OK - covariant type parameter
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Extra Columns are Ignored
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from typing import Protocol
|
|
166
|
+
import pandas as pd
|
|
167
|
+
from pavise.pandas import DataFrame
|
|
168
|
+
|
|
169
|
+
class SimpleSchema(Protocol):
|
|
170
|
+
a: int
|
|
171
|
+
|
|
172
|
+
# Extra columns are ignored during validation
|
|
173
|
+
df = pd.DataFrame({
|
|
174
|
+
'a': [1, 2, 3],
|
|
175
|
+
'b': ['x', 'y', 'z'], # Extra column - ignored
|
|
176
|
+
'c': [10.0, 20.0, 30.0] # Extra column - ignored
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
validated = DataFrame[SimpleSchema](df) # OK
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Supported Types
|
|
183
|
+
|
|
184
|
+
- `int`
|
|
185
|
+
- `float`
|
|
186
|
+
- `str`
|
|
187
|
+
- `bool`
|
|
188
|
+
|
|
189
|
+
## Development
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Install with dev dependencies (includes both pandas and polars)
|
|
193
|
+
uv pip install -e ".[dev]"
|
|
194
|
+
|
|
195
|
+
# Run all tests
|
|
196
|
+
uv run pytest
|
|
197
|
+
|
|
198
|
+
# Run tests for specific backend
|
|
199
|
+
uv run pytest tests/test_pandas.py
|
|
200
|
+
uv run pytest tests/test_polars.py
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Testing with tox
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Run tests for all Python versions and backends
|
|
207
|
+
tox
|
|
208
|
+
|
|
209
|
+
# Run tests for specific environment
|
|
210
|
+
tox -e py312-pandas # Test pandas backend with Python 3.12
|
|
211
|
+
tox -e py312-polars # Test polars backend with Python 3.12
|
|
212
|
+
tox -e py312-all # Test both backends with Python 3.12
|
|
213
|
+
|
|
214
|
+
# Run linting
|
|
215
|
+
tox -e lint
|
|
216
|
+
|
|
217
|
+
# Run type checking
|
|
218
|
+
tox -e type
|
|
219
|
+
|
|
220
|
+
# Available Python versions: py39, py310, py311, py312
|
|
221
|
+
# Available backends: pandas, polars, all
|
|
222
|
+
```
|
pavise-0.0.1/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Pavise
|
|
2
|
+
|
|
3
|
+
DataFrame validation library using Python Protocol for structural subtyping.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Use Python Protocol to define DataFrame schemas
|
|
8
|
+
- `DataFrame[Schema]` type annotation for static type checking
|
|
9
|
+
- Structural subtyping: validate only required columns, ignore extra columns
|
|
10
|
+
- Covariant type parameters: `DataFrame[ChildSchema]` is compatible with `DataFrame[ParentSchema]`
|
|
11
|
+
- Optional runtime validation
|
|
12
|
+
- No inheritance required
|
|
13
|
+
- Support for both pandas and polars backends
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# For pandas support
|
|
19
|
+
pip install pavise[pandas]
|
|
20
|
+
|
|
21
|
+
# For polars support
|
|
22
|
+
pip install pavise[polars]
|
|
23
|
+
|
|
24
|
+
# For both
|
|
25
|
+
pip install pavise[all]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Pandas Backend
|
|
31
|
+
|
|
32
|
+
#### Static Type Checking Only (Recommended)
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from typing import Protocol
|
|
36
|
+
from pavise.pandas import DataFrame
|
|
37
|
+
|
|
38
|
+
class UserSchema(Protocol):
|
|
39
|
+
name: str
|
|
40
|
+
age: int
|
|
41
|
+
|
|
42
|
+
def process_users(df: DataFrame[UserSchema]) -> DataFrame[UserSchema]:
|
|
43
|
+
# mypy/pyrefly will check types, no runtime validation
|
|
44
|
+
return df[df['age'] >= 18]
|
|
45
|
+
|
|
46
|
+
# Use regular pandas DataFrame
|
|
47
|
+
import pandas as pd
|
|
48
|
+
df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
49
|
+
result = process_users(df)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Runtime Validation (Explicit)
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from typing import Protocol
|
|
56
|
+
import pandas as pd
|
|
57
|
+
from pavise.pandas import DataFrame
|
|
58
|
+
|
|
59
|
+
class UserSchema(Protocol):
|
|
60
|
+
name: str
|
|
61
|
+
age: int
|
|
62
|
+
|
|
63
|
+
def load_users(raw_df: pd.DataFrame) -> DataFrame[UserSchema]:
|
|
64
|
+
# Validate at runtime when needed
|
|
65
|
+
return DataFrame[UserSchema](raw_df)
|
|
66
|
+
|
|
67
|
+
raw_df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
68
|
+
validated_df = load_users(raw_df) # Runtime validation occurs here
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Polars Backend
|
|
72
|
+
|
|
73
|
+
#### Static Type Checking Only (Recommended)
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from typing import Protocol
|
|
77
|
+
from pavise.polars import DataFrame
|
|
78
|
+
|
|
79
|
+
class UserSchema(Protocol):
|
|
80
|
+
name: str
|
|
81
|
+
age: int
|
|
82
|
+
|
|
83
|
+
def process_users(df: DataFrame[UserSchema]) -> DataFrame[UserSchema]:
|
|
84
|
+
# mypy/pyrefly will check types, no runtime validation
|
|
85
|
+
return df.filter(df['age'] >= 18)
|
|
86
|
+
|
|
87
|
+
# Use regular polars DataFrame
|
|
88
|
+
import polars as pl
|
|
89
|
+
df = pl.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
90
|
+
result = process_users(df)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Runtime Validation (Explicit)
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from typing import Protocol
|
|
97
|
+
import polars as pl
|
|
98
|
+
from pavise.polars import DataFrame
|
|
99
|
+
|
|
100
|
+
class UserSchema(Protocol):
|
|
101
|
+
name: str
|
|
102
|
+
age: int
|
|
103
|
+
|
|
104
|
+
def load_users(raw_df: pl.DataFrame) -> DataFrame[UserSchema]:
|
|
105
|
+
# Validate at runtime when needed
|
|
106
|
+
return DataFrame[UserSchema](raw_df)
|
|
107
|
+
|
|
108
|
+
raw_df = pl.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 17]})
|
|
109
|
+
validated_df = load_users(raw_df) # Runtime validation occurs here
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Structural Subtyping
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from typing import Protocol
|
|
116
|
+
import pandas as pd
|
|
117
|
+
from pavise.pandas import DataFrame
|
|
118
|
+
|
|
119
|
+
class UserSchema(Protocol):
|
|
120
|
+
name: str
|
|
121
|
+
|
|
122
|
+
class UserWithEmailSchema(Protocol):
|
|
123
|
+
name: str
|
|
124
|
+
email: str
|
|
125
|
+
|
|
126
|
+
def process_user(df: DataFrame[UserSchema]) -> None:
|
|
127
|
+
print(df['name'])
|
|
128
|
+
|
|
129
|
+
# This works! UserWithEmailSchema has all required columns of UserSchema
|
|
130
|
+
df: DataFrame[UserWithEmailSchema] = pd.DataFrame({
|
|
131
|
+
'name': ['Alice'],
|
|
132
|
+
'email': ['alice@example.com']
|
|
133
|
+
})
|
|
134
|
+
process_user(df) # OK - covariant type parameter
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Extra Columns are Ignored
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from typing import Protocol
|
|
141
|
+
import pandas as pd
|
|
142
|
+
from pavise.pandas import DataFrame
|
|
143
|
+
|
|
144
|
+
class SimpleSchema(Protocol):
|
|
145
|
+
a: int
|
|
146
|
+
|
|
147
|
+
# Extra columns are ignored during validation
|
|
148
|
+
df = pd.DataFrame({
|
|
149
|
+
'a': [1, 2, 3],
|
|
150
|
+
'b': ['x', 'y', 'z'], # Extra column - ignored
|
|
151
|
+
'c': [10.0, 20.0, 30.0] # Extra column - ignored
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
validated = DataFrame[SimpleSchema](df) # OK
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Supported Types
|
|
158
|
+
|
|
159
|
+
- `int`
|
|
160
|
+
- `float`
|
|
161
|
+
- `str`
|
|
162
|
+
- `bool`
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Install with dev dependencies (includes both pandas and polars)
|
|
168
|
+
uv pip install -e ".[dev]"
|
|
169
|
+
|
|
170
|
+
# Run all tests
|
|
171
|
+
uv run pytest
|
|
172
|
+
|
|
173
|
+
# Run tests for specific backend
|
|
174
|
+
uv run pytest tests/test_pandas.py
|
|
175
|
+
uv run pytest tests/test_polars.py
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Testing with tox
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Run tests for all Python versions and backends
|
|
182
|
+
tox
|
|
183
|
+
|
|
184
|
+
# Run tests for specific environment
|
|
185
|
+
tox -e py312-pandas # Test pandas backend with Python 3.12
|
|
186
|
+
tox -e py312-polars # Test polars backend with Python 3.12
|
|
187
|
+
tox -e py312-all # Test both backends with Python 3.12
|
|
188
|
+
|
|
189
|
+
# Run linting
|
|
190
|
+
tox -e lint
|
|
191
|
+
|
|
192
|
+
# Run type checking
|
|
193
|
+
tox -e type
|
|
194
|
+
|
|
195
|
+
# Available Python versions: py39, py310, py311, py312
|
|
196
|
+
# Available backends: pandas, polars, all
|
|
197
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "uv-dynamic-versioning"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pavise"
|
|
7
|
+
description = "DataFrame validation library using Python Protocol for structural subtyping"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "kitagry"},
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"typing-extensions>=4.0.0",
|
|
16
|
+
]
|
|
17
|
+
dynamic = ["version"]
|
|
18
|
+
|
|
19
|
+
[tool.hatch.version]
|
|
20
|
+
source = "uv-dynamic-versioning"
|
|
21
|
+
|
|
22
|
+
[tool.uv-dynamic-versioning]
|
|
23
|
+
enable = true
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.hooks.version]
|
|
26
|
+
path = "src/pavise/__init__.py"
|
|
27
|
+
template = '''
|
|
28
|
+
"""Pavise: DataFrame validation library using Python Protocol for structural subtyping."""
|
|
29
|
+
|
|
30
|
+
__version__ = "{version}"
|
|
31
|
+
__all__ = []
|
|
32
|
+
'''
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
pandas = [
|
|
36
|
+
"pandas>=1.3.0",
|
|
37
|
+
]
|
|
38
|
+
polars = [
|
|
39
|
+
"polars>=0.15.0",
|
|
40
|
+
]
|
|
41
|
+
all = [
|
|
42
|
+
"pandas>=1.3.0",
|
|
43
|
+
"polars>=0.15.0",
|
|
44
|
+
]
|
|
45
|
+
dev = [
|
|
46
|
+
"pytest>=7.0.0",
|
|
47
|
+
"pytest-cov>=4.0.0",
|
|
48
|
+
"pyrefly>=0.1.0",
|
|
49
|
+
"ruff>=0.1.0",
|
|
50
|
+
"tox>=4.0.0",
|
|
51
|
+
"pandas>=1.3.0",
|
|
52
|
+
"polars>=0.15.0",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/pavise"]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
60
|
+
pythonpath = ["src"]
|
|
61
|
+
|
|
62
|
+
[tool.pyrefly]
|
|
63
|
+
python_version = "3.9"
|
|
64
|
+
|
|
65
|
+
[tool.ruff]
|
|
66
|
+
line-length = 100
|
|
67
|
+
target-version = "py39"
|
|
68
|
+
|
|
69
|
+
[tool.ruff.lint]
|
|
70
|
+
select = ["E", "F", "I", "N", "W", "UP"]
|
|
71
|
+
ignore = []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Pandas-specific implementation details."""
|