remove nptyping dependency, update CI, remove old numpy types

This commit is contained in:
sneakers-the-rat 2024-07-31 15:50:24 -07:00
parent 3306703741
commit 40c8e9d95d
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
10 changed files with 90 additions and 144 deletions

28
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: Lint
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
jobs:
ruff:
name: Ruff Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
black:
name: Black Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable

View file

@ -2,14 +2,34 @@ name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
strategy:
matrix:
python-version: ["3.9", "3.11", "3.12"]
platform: ["ubuntu-latest", "macos-latest", "windows-latest"]
numpy-version: ["<2.0.0", ">=2.0.0"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
exclude:
- numpy-version: "<2.0.0"
python-version: "3.10"
- numpy-version: "<2.0.0"
python-version: "3.11"
- platform: "macos-latest"
python-version: "3.10"
- platform: "macos-latest"
python-version: "3.11"
- platform: "windows-latest"
python-version: "3.10"
- platform: "windows-latest"
python-version: "3.11"
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
@ -23,19 +43,24 @@ jobs:
- name: Install dependencies
run: pip install -e ".[tests,linkml]"
- name: Install numpy version
run: pip install "numpy${{ matrix.numpy-version }}"
- name: Run Tests
run: pytest
- name: Report coverage
if: ${{ matrix.python-version }} == "3.11"
run: "coveralls --service=github"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Coveralls Parallel
uses: coverallsapp/github-action@v2
with:
flag-name: run-${{ join(matrix.*, '-') }}
parallel: true
lint:
finish-coverage:
needs: test
if: ${{ always() }}
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
- uses: psf/black@stable
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true

View file

@ -7,8 +7,8 @@ authors = [
]
dependencies = [
"pydantic>=2.3.0",
"nptyping>=2.5.0",
"numpy>=1.24.0",
"typing-extensions>=4.11.0;python_version<'3.11'"
]
homepage = "https://numpydantic.readthedocs.io"
requires-python = "<4.0,>=3.9"
@ -40,7 +40,6 @@ tests = [
"coverage>=6.1.1",
"pytest-cov<5.0.0,>=4.1.0",
"coveralls<4.0.0,>=3.3.1",
"typing-extensions>=4.11.0;python_version<'3.11'",
]
docs = [
"sphinx<8.0.0,>=7.2.6",

View file

@ -78,14 +78,12 @@ Float = (
)
Floating = Float
ComplexFloating = np.complexfloating
Complex64 = np.complex64
Complex128 = np.complex128
CSingle = np.csingle
CDouble = np.cdouble
CLongDouble = np.clongdouble
Complex = (
np.complexfloating,
np.complex64,
np.complex128,
np.csingle,

View file

@ -50,7 +50,7 @@ def _lol_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema:
if isinstance(dtype, tuple):
# if it's a meta-type that refers to a generic float/int, just make that
if dtype == dt.Float:
if dtype in (dt.Float, dt.Number):
array_type = core_schema.float_schema()
elif dtype == dt.Integer:
array_type = core_schema.int_schema()

View file

@ -42,10 +42,8 @@ from numpydantic.vendor.nptyping.shape_expression import (
from numpydantic.vendor.nptyping.structure import Structure
from numpydantic.vendor.nptyping.typing_ import (
Bool,
Bool8,
Byte,
Bytes,
Bytes0,
CDouble,
CFloat,
Character,
@ -68,7 +66,6 @@ from numpydantic.vendor.nptyping.typing_ import (
Half,
Inexact,
Int,
Int0,
Int8,
Int16,
Int32,
@ -82,17 +79,14 @@ from numpydantic.vendor.nptyping.typing_ import (
LongLong,
Number,
Object,
Object0,
Short,
SignedInteger,
Single,
SingleComplex,
Str0,
String,
Timedelta64,
UByte,
UInt,
UInt0,
UInt8,
UInt16,
UInt32,
@ -104,7 +98,6 @@ from numpydantic.vendor.nptyping.typing_ import (
UnsignedInteger,
UShort,
Void,
Void0,
)
__all__ = [

View file

@ -22,11 +22,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from typing import ( # type: ignore[attr-defined,misc] # pylint: disable=unused-import
Tuple,
TypeAlias,
Union,
)
import sys
from typing import Tuple, Union
if sys.version_info.minor >= 10:
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
import numpy as np

View file

@ -1,114 +0,0 @@
"""
MIT License
Copyright (c) 2023 Ramon Hagenaars
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.
"""
try:
from typing import ( # type: ignore[attr-defined] # pylint: disable=unused-import
Dict,
TypeAlias,
)
except ImportError: # pragma: no cover
from typing_extensions import (
TypeAlias,
)
from typing import (
Any,
Tuple,
Union,
)
import numpy as np
ShapeExpression: TypeAlias = str
StructureExpression: TypeAlias = str
DType: TypeAlias = Union[np.generic, StructureExpression]
ShapeTuple: TypeAlias = Tuple[int, ...]
Number: TypeAlias = np.dtype[np.number[Any]]
Bool: TypeAlias = np.dtype[np.bool_]
Bool8: TypeAlias = np.dtype[np.bool8]
Object: TypeAlias = np.dtype[np.object_]
Object0: TypeAlias = np.dtype[np.object0]
Datetime64: TypeAlias = np.dtype[np.datetime64]
Integer: TypeAlias = np.dtype[np.integer[Any]]
SignedInteger: TypeAlias = np.dtype[np.signedinteger[Any]]
Int8: TypeAlias = np.dtype[np.int8]
Int16: TypeAlias = np.dtype[np.int16]
Int32: TypeAlias = np.dtype[np.int32]
Int64: TypeAlias = np.dtype[np.int64]
Byte: TypeAlias = np.dtype[np.byte]
Short: TypeAlias = np.dtype[np.short]
IntC: TypeAlias = np.dtype[np.intc]
IntP: TypeAlias = np.dtype[np.intp]
Int0: TypeAlias = np.dtype[np.int0]
Int: TypeAlias = np.dtype[np.int_]
LongLong: TypeAlias = np.dtype[np.longlong]
Timedelta64: TypeAlias = np.dtype[np.timedelta64]
UnsignedInteger: TypeAlias = np.dtype[np.unsignedinteger[Any]]
UInt8: TypeAlias = np.dtype[np.uint8]
UInt16: TypeAlias = np.dtype[np.uint16]
UInt32: TypeAlias = np.dtype[np.uint32]
UInt64: TypeAlias = np.dtype[np.uint64]
UByte: TypeAlias = np.dtype[np.ubyte]
UShort: TypeAlias = np.dtype[np.ushort]
UIntC: TypeAlias = np.dtype[np.uintc]
UIntP: TypeAlias = np.dtype[np.uintp]
UInt0: TypeAlias = np.dtype[np.uint0]
UInt: TypeAlias = np.dtype[np.uint]
ULongLong: TypeAlias = np.dtype[np.ulonglong]
Inexact: TypeAlias = np.dtype[np.inexact[Any]]
Floating: TypeAlias = np.dtype[np.floating[Any]]
Float16: TypeAlias = np.dtype[np.float16]
Float32: TypeAlias = np.dtype[np.float32]
Float64: TypeAlias = np.dtype[np.float64]
Half: TypeAlias = np.dtype[np.half]
Single: TypeAlias = np.dtype[np.single]
Double: TypeAlias = np.dtype[np.double]
Float: TypeAlias = np.dtype[np.float_]
LongDouble: TypeAlias = np.dtype[np.longdouble]
LongFloat: TypeAlias = np.dtype[np.longfloat]
ComplexFloating: TypeAlias = np.dtype[np.complexfloating[Any, Any]]
Complex64: TypeAlias = np.dtype[np.complex64]
Complex128: TypeAlias = np.dtype[np.complex128]
CSingle: TypeAlias = np.dtype[np.csingle]
SingleComplex: TypeAlias = np.dtype[np.singlecomplex]
CDouble: TypeAlias = np.dtype[np.cdouble]
Complex: TypeAlias = np.dtype[np.complex_]
CFloat: TypeAlias = np.dtype[np.cfloat]
CLongDouble: TypeAlias = np.dtype[np.clongdouble]
CLongFloat: TypeAlias = np.dtype[np.clongfloat]
LongComplex: TypeAlias = np.dtype[np.longcomplex]
Flexible: TypeAlias = np.dtype[np.flexible]
Void: TypeAlias = np.dtype[np.void]
Void0: TypeAlias = np.dtype[np.void0]
Character: TypeAlias = np.dtype[np.character]
Bytes: TypeAlias = np.dtype[np.bytes_]
Str: TypeAlias = np.dtype[np.str_]
String: TypeAlias = np.dtype[np.string_]
Bytes0: TypeAlias = np.dtype[np.bytes0]
Unicode: TypeAlias = np.dtype[np.unicode_]
Str0: TypeAlias = np.dtype[np.str0]
dtype_per_name: Dict[str, np.dtype[Any]]
name_per_dtype: Dict[np.dtype[Any], str]

View file

@ -7,11 +7,12 @@ import json
import numpy as np
from pydantic import BaseModel, ValidationError, Field
from nptyping import Number
from numpydantic import NDArray, Shape
from numpydantic.exceptions import ShapeError, DtypeError
from numpydantic import dtype
from numpydantic.dtype import Number
def test_ndarray_type():

14
tox.ini Normal file
View file

@ -0,0 +1,14 @@
[tox]
requires =
tox>=4
env_list = py{39,310,311,312}-numpy{1,2}
[testenv]
package = editable
extras =
tests
deps =
py{39,310,311,312}-numpy1: numpy<2.0.0
py{39,310,311,312}-numpy2: numpy>=2.0.0
commands =
python -m pytest