From 4c911d2516317850137d7d0c8ddb24d253c21f12 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Wed, 31 Jul 2024 14:08:01 -0700 Subject: [PATCH] update import location --- src/numpydantic/ndarray.py | 12 +++++------ src/numpydantic/schema.py | 4 ++-- src/numpydantic/shape.py | 10 ++++----- src/numpydantic/vendor/nptyping/__init__.py | 20 +++++++++--------- .../vendor/nptyping/base_meta_classes.py | 13 ++++++++---- src/numpydantic/vendor/nptyping/ndarray.py | 21 +++++++++++-------- .../vendor/nptyping/pandas_/dataframe.py | 16 +++++++------- .../vendor/nptyping/pandas_/typing_.py | 4 ++-- src/numpydantic/vendor/nptyping/recarray.py | 11 +++++----- src/numpydantic/vendor/nptyping/shape.py | 6 +++--- .../vendor/nptyping/shape_expression.py | 4 ++-- src/numpydantic/vendor/nptyping/structure.py | 6 +++--- src/numpydantic/vendor/nptyping/structure.pyi | 11 +++++++++- .../vendor/nptyping/structure_expression.py | 8 +++---- 14 files changed, 82 insertions(+), 64 deletions(-) diff --git a/src/numpydantic/ndarray.py b/src/numpydantic/ndarray.py index 5ad42ba..81efb7f 100644 --- a/src/numpydantic/ndarray.py +++ b/src/numpydantic/ndarray.py @@ -16,12 +16,12 @@ Extension of nptyping NDArray for pydantic that allows for JSON-Schema serializa from typing import TYPE_CHECKING, Any, Tuple import numpy as np -from nptyping.error import InvalidArgumentsError -from nptyping.ndarray import NDArrayMeta as _NDArrayMeta -from nptyping.nptyping_type import NPTypingType -from nptyping.structure import Structure -from nptyping.structure_expression import check_type_names -from nptyping.typing_ import ( +from numpydantic.vendor.nptyping.error import InvalidArgumentsError +from numpydantic.vendor.nptyping.ndarray import NDArrayMeta as _NDArrayMeta +from numpydantic.vendor.nptyping.nptyping_type import NPTypingType +from numpydantic.vendor.nptyping.structure import Structure +from numpydantic.vendor.nptyping.structure_expression import check_type_names +from numpydantic.vendor.nptyping.typing_ import ( dtype_per_name, ) from pydantic import GetJsonSchemaHandler diff --git a/src/numpydantic/schema.py b/src/numpydantic/schema.py index 084ac7c..0a6c568 100644 --- a/src/numpydantic/schema.py +++ b/src/numpydantic/schema.py @@ -7,7 +7,7 @@ import hashlib import json from typing import TYPE_CHECKING, Any, Callable, Optional, Union -import nptyping.structure +from numpydantic.vendor.nptyping.structure import StructureMeta import numpy as np from pydantic import SerializationInfo from pydantic_core import CoreSchema, core_schema @@ -45,7 +45,7 @@ def _numeric_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema: def _lol_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema: """Get the innermost dtype schema to use in the generated pydantic schema""" - if isinstance(dtype, nptyping.structure.StructureMeta): # pragma: no cover + if isinstance(dtype, StructureMeta): # pragma: no cover raise NotImplementedError("Structured dtypes are currently unsupported") if isinstance(dtype, tuple): diff --git a/src/numpydantic/shape.py b/src/numpydantic/shape.py index 366e572..62a567f 100644 --- a/src/numpydantic/shape.py +++ b/src/numpydantic/shape.py @@ -29,15 +29,15 @@ from abc import ABC from functools import lru_cache from typing import Any, Dict, List, Union -from nptyping.base_meta_classes import ContainerMeta -from nptyping.error import InvalidShapeError, NPTypingError -from nptyping.nptyping_type import NPTypingType -from nptyping.shape_expression import ( +from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta +from numpydantic.vendor.nptyping.error import InvalidShapeError, NPTypingError +from numpydantic.vendor.nptyping.nptyping_type import NPTypingType +from numpydantic.vendor.nptyping.shape_expression import ( get_dimensions, normalize_shape_expression, remove_labels, ) -from nptyping.typing_ import ShapeExpression, ShapeTuple +from numpydantic.vendor.nptyping.typing_ import ShapeExpression, ShapeTuple class ShapeMeta(ContainerMeta, implementation="Shape"): diff --git a/src/numpydantic/vendor/nptyping/__init__.py b/src/numpydantic/vendor/nptyping/__init__.py index 35e11cc..8641108 100644 --- a/src/numpydantic/vendor/nptyping/__init__.py +++ b/src/numpydantic/vendor/nptyping/__init__.py @@ -22,25 +22,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from nptyping.assert_isinstance import assert_isinstance -from nptyping.error import ( +from numpydantic.vendor.nptyping.assert_isinstance import assert_isinstance +from numpydantic.vendor.nptyping.error import ( InvalidArgumentsError, InvalidDTypeError, InvalidShapeError, InvalidStructureError, NPTypingError, ) -from nptyping.ndarray import NDArray -from nptyping.package_info import __version__ -from nptyping.pandas_.dataframe import DataFrame -from nptyping.recarray import RecArray -from nptyping.shape import Shape -from nptyping.shape_expression import ( +from numpydantic.vendor.nptyping.ndarray import NDArray +from numpydantic.vendor.nptyping.package_info import __version__ +from numpydantic.vendor.nptyping.pandas_.dataframe import DataFrame +from numpydantic.vendor.nptyping.recarray import RecArray +from numpydantic.vendor.nptyping.shape import Shape +from numpydantic.vendor.nptyping.shape_expression import ( normalize_shape_expression, validate_shape_expression, ) -from nptyping.structure import Structure -from nptyping.typing_ import ( +from numpydantic.vendor.nptyping.structure import Structure +from numpydantic.vendor.nptyping.typing_ import ( Bool, Bool8, Byte, diff --git a/src/numpydantic/vendor/nptyping/base_meta_classes.py b/src/numpydantic/vendor/nptyping/base_meta_classes.py index c2ca1e3..01b5c12 100644 --- a/src/numpydantic/vendor/nptyping/base_meta_classes.py +++ b/src/numpydantic/vendor/nptyping/base_meta_classes.py @@ -23,7 +23,8 @@ SOFTWARE. """ from abc import ABCMeta, abstractmethod -from inspect import FrameInfo +from inspect import FrameInfo, getframeinfo +from types import FrameType from typing import ( Any, Dict, @@ -34,7 +35,7 @@ from typing import ( TypeVar, ) -from nptyping.error import InvalidArgumentsError, NPTypingError +from numpydantic.vendor.nptyping.error import InvalidArgumentsError, NPTypingError _T = TypeVar("_T") @@ -126,10 +127,14 @@ class SubscriptableMeta(ABCMeta): @abstractmethod def _get_item(cls, item: Any) -> Tuple[Any, ...]: ... # pragma: no cover - def _get_module(cls, stack: List[FrameInfo], module: str) -> str: + def _get_module(cls, stack: FrameType, module: str) -> str: # The magic below makes Python's help function display a meaningful # text with nptyping types. - return "typing" if stack[1][3] == "formatannotation" else module + return ( + "typing" + if getframeinfo(stack.f_back).function == "formatannotation" + else module + ) def _get_additional_values( cls, item: Any # pylint: disable=unused-argument diff --git a/src/numpydantic/vendor/nptyping/ndarray.py b/src/numpydantic/vendor/nptyping/ndarray.py index a3a8daf..c891af5 100644 --- a/src/numpydantic/vendor/nptyping/ndarray.py +++ b/src/numpydantic/vendor/nptyping/ndarray.py @@ -27,7 +27,7 @@ from abc import ABC from typing import Any, Tuple import numpy as np -from nptyping.base_meta_classes import ( +from numpydantic.vendor.nptyping.base_meta_classes import ( FinalMeta, ImmutableMeta, InconstructableMeta, @@ -35,13 +35,16 @@ from nptyping.base_meta_classes import ( PrintableMeta, SubscriptableMeta, ) -from nptyping.error import InvalidArgumentsError -from nptyping.nptyping_type import NPTypingType -from nptyping.shape import Shape -from nptyping.shape_expression import check_shape -from nptyping.structure import Structure -from nptyping.structure_expression import check_structure, check_type_names -from nptyping.typing_ import ( +from numpydantic.vendor.nptyping.error import InvalidArgumentsError +from numpydantic.vendor.nptyping.nptyping_type import NPTypingType +from numpydantic.vendor.nptyping.shape import Shape +from numpydantic.vendor.nptyping.shape_expression import check_shape +from numpydantic.vendor.nptyping.structure import Structure +from numpydantic.vendor.nptyping.structure_expression import ( + check_structure, + check_type_names, +) +from numpydantic.vendor.nptyping.typing_ import ( DType, dtype_per_name, name_per_dtype, @@ -67,7 +70,7 @@ class NDArrayMeta( @property def __module__(cls) -> str: - return cls._get_module(inspect.stack(), "nptyping.ndarray") + return cls._get_module(inspect.currentframe(), "nptyping.ndarray") def _get_item(cls, item: Any) -> Tuple[Any, ...]: cls._check_item(item) diff --git a/src/numpydantic/vendor/nptyping/pandas_/dataframe.py b/src/numpydantic/vendor/nptyping/pandas_/dataframe.py index 9dd5ee7..dd270cf 100644 --- a/src/numpydantic/vendor/nptyping/pandas_/dataframe.py +++ b/src/numpydantic/vendor/nptyping/pandas_/dataframe.py @@ -27,8 +27,8 @@ from abc import ABC from typing import Any, Tuple import numpy as np -from nptyping import InvalidArgumentsError -from nptyping.base_meta_classes import ( +from numpydantic.vendor.nptyping import InvalidArgumentsError +from numpydantic.vendor.nptyping.base_meta_classes import ( FinalMeta, ImmutableMeta, InconstructableMeta, @@ -36,11 +36,11 @@ from nptyping.base_meta_classes import ( PrintableMeta, SubscriptableMeta, ) -from nptyping.error import DependencyError -from nptyping.nptyping_type import NPTypingType -from nptyping.pandas_.typing_ import dtype_per_name -from nptyping.structure import Structure -from nptyping.structure_expression import check_structure +from numpydantic.vendor.nptyping.error import DependencyError +from numpydantic.vendor.nptyping.nptyping_type import NPTypingType +from numpydantic.vendor.nptyping.pandas_.typing_ import dtype_per_name +from numpydantic.vendor.nptyping.structure import Structure +from numpydantic.vendor.nptyping.structure_expression import check_structure try: import pandas as pd @@ -105,7 +105,7 @@ class DataFrameMeta( @property def __module__(cls) -> str: - return cls._get_module(inspect.stack(), "nptyping.pandas_.dataframe") + return cls._get_module(inspect.currentframe(), "nptyping.ndarray") def _check_item(cls, item: Any) -> None: # Check if the item is what we expect and raise if it is not. diff --git a/src/numpydantic/vendor/nptyping/pandas_/typing_.py b/src/numpydantic/vendor/nptyping/pandas_/typing_.py index 37dfdbe..461fa1f 100644 --- a/src/numpydantic/vendor/nptyping/pandas_/typing_.py +++ b/src/numpydantic/vendor/nptyping/pandas_/typing_.py @@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from nptyping.typing_ import Object -from nptyping.typing_ import dtype_per_name as dtype_per_name_default +from numpydantic.vendor.nptyping.typing_ import Object +from numpydantic.vendor.nptyping.typing_ import dtype_per_name as dtype_per_name_default dtype_per_name = { **dtype_per_name_default, # type: ignore[arg-type] diff --git a/src/numpydantic/vendor/nptyping/recarray.py b/src/numpydantic/vendor/nptyping/recarray.py index a90b13b..931a135 100644 --- a/src/numpydantic/vendor/nptyping/recarray.py +++ b/src/numpydantic/vendor/nptyping/recarray.py @@ -26,10 +26,11 @@ import inspect from typing import Any, Tuple import numpy as np -from nptyping.error import InvalidArgumentsError -from nptyping.ndarray import NDArray, NDArrayMeta -from nptyping.structure import Structure -from nptyping.typing_ import DType + +from numpydantic.vendor.nptyping.error import InvalidArgumentsError +from numpydantic.vendor.nptyping.ndarray import NDArray, NDArrayMeta +from numpydantic.vendor.nptyping.structure import Structure +from numpydantic.vendor.nptyping.typing_ import DType class RecArrayMeta(NDArrayMeta, implementation="RecArray"): @@ -52,7 +53,7 @@ class RecArrayMeta(NDArrayMeta, implementation="RecArray"): @property def __module__(cls) -> str: - return cls._get_module(inspect.stack(), "nptyping.recarray") + return cls._get_module(inspect.currentframe(), "nptyping.ndarray") def __instancecheck__( # pylint: disable=bad-mcs-method-argument self, instance: Any diff --git a/src/numpydantic/vendor/nptyping/shape.py b/src/numpydantic/vendor/nptyping/shape.py index c30aefc..b4d4698 100644 --- a/src/numpydantic/vendor/nptyping/shape.py +++ b/src/numpydantic/vendor/nptyping/shape.py @@ -25,9 +25,9 @@ SOFTWARE. from abc import ABC from typing import Any, Dict -from nptyping.base_meta_classes import ContainerMeta -from nptyping.nptyping_type import NPTypingType -from nptyping.shape_expression import ( +from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta +from numpydantic.vendor.nptyping.nptyping_type import NPTypingType +from numpydantic.vendor.nptyping.shape_expression import ( get_dimensions, normalize_shape_expression, remove_labels, diff --git a/src/numpydantic/vendor/nptyping/shape_expression.py b/src/numpydantic/vendor/nptyping/shape_expression.py index 8d55a56..6234031 100644 --- a/src/numpydantic/vendor/nptyping/shape_expression.py +++ b/src/numpydantic/vendor/nptyping/shape_expression.py @@ -33,8 +33,8 @@ from typing import ( Union, ) -from nptyping.error import InvalidShapeError -from nptyping.typing_ import ShapeExpression, ShapeTuple +from numpydantic.vendor.nptyping.error import InvalidShapeError +from numpydantic.vendor.nptyping.typing_ import ShapeExpression, ShapeTuple if TYPE_CHECKING: from nptyping.shape import Shape # pragma: no cover diff --git a/src/numpydantic/vendor/nptyping/structure.py b/src/numpydantic/vendor/nptyping/structure.py index 71da5ef..8ad5d5b 100644 --- a/src/numpydantic/vendor/nptyping/structure.py +++ b/src/numpydantic/vendor/nptyping/structure.py @@ -29,9 +29,9 @@ from typing import ( List, ) -from nptyping.base_meta_classes import ContainerMeta -from nptyping.nptyping_type import NPTypingType -from nptyping.structure_expression import ( +from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta +from numpydantic.vendor.nptyping.nptyping_type import NPTypingType +from numpydantic.vendor.nptyping.structure_expression import ( create_name_to_type_dict, normalize_structure_expression, validate_structure_expression, diff --git a/src/numpydantic/vendor/nptyping/structure.pyi b/src/numpydantic/vendor/nptyping/structure.pyi index 608c094..a0ba8eb 100644 --- a/src/numpydantic/vendor/nptyping/structure.pyi +++ b/src/numpydantic/vendor/nptyping/structure.pyi @@ -27,9 +27,18 @@ try: except ImportError: from typing_extensions import Literal # type: ignore[attr-defined,misc,assignment] -from typing import Any, cast +from typing import Any, Dict, cast import numpy as np +from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta + +class StructureMeta(ContainerMeta, implementation="Structure"): + + __args__ = tuple() + + def _validate_expression(cls, item: str) -> None: ... + def _normalize_expression(cls, item: str) -> str: ... + def _get_additional_values(cls, item: Any) -> Dict[str, Any]: ... # For MyPy: Structure = cast(Literal, Structure) # type: ignore[has-type,misc,valid-type] diff --git a/src/numpydantic/vendor/nptyping/structure_expression.py b/src/numpydantic/vendor/nptyping/structure_expression.py index f175381..dd9d8f1 100644 --- a/src/numpydantic/vendor/nptyping/structure_expression.py +++ b/src/numpydantic/vendor/nptyping/structure_expression.py @@ -38,14 +38,14 @@ from typing import ( ) import numpy as np -from nptyping.error import InvalidShapeError, InvalidStructureError -from nptyping.shape import Shape -from nptyping.shape_expression import ( +from numpydantic.vendor.nptyping.error import InvalidShapeError, InvalidStructureError +from numpydantic.vendor.nptyping.shape import Shape +from numpydantic.vendor.nptyping.shape_expression import ( check_shape, normalize_shape_expression, validate_shape_expression, ) -from nptyping.typing_ import StructureExpression +from numpydantic.vendor.nptyping.typing_ import StructureExpression if TYPE_CHECKING: from nptyping.structure import Structure # pragma: no cover