update import location

This commit is contained in:
sneakers-the-rat 2024-07-31 14:08:01 -07:00
parent dba550f41b
commit 4c911d2516
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
14 changed files with 82 additions and 64 deletions

View file

@ -16,12 +16,12 @@ Extension of nptyping NDArray for pydantic that allows for JSON-Schema serializa
from typing import TYPE_CHECKING, Any, Tuple from typing import TYPE_CHECKING, Any, Tuple
import numpy as np import numpy as np
from nptyping.error import InvalidArgumentsError from numpydantic.vendor.nptyping.error import InvalidArgumentsError
from nptyping.ndarray import NDArrayMeta as _NDArrayMeta from numpydantic.vendor.nptyping.ndarray import NDArrayMeta as _NDArrayMeta
from nptyping.nptyping_type import NPTypingType from numpydantic.vendor.nptyping.nptyping_type import NPTypingType
from nptyping.structure import Structure from numpydantic.vendor.nptyping.structure import Structure
from nptyping.structure_expression import check_type_names from numpydantic.vendor.nptyping.structure_expression import check_type_names
from nptyping.typing_ import ( from numpydantic.vendor.nptyping.typing_ import (
dtype_per_name, dtype_per_name,
) )
from pydantic import GetJsonSchemaHandler from pydantic import GetJsonSchemaHandler

View file

@ -7,7 +7,7 @@ import hashlib
import json import json
from typing import TYPE_CHECKING, Any, Callable, Optional, Union from typing import TYPE_CHECKING, Any, Callable, Optional, Union
import nptyping.structure from numpydantic.vendor.nptyping.structure import StructureMeta
import numpy as np import numpy as np
from pydantic import SerializationInfo from pydantic import SerializationInfo
from pydantic_core import CoreSchema, core_schema 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: def _lol_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema:
"""Get the innermost dtype schema to use in the generated pydantic schema""" """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") raise NotImplementedError("Structured dtypes are currently unsupported")
if isinstance(dtype, tuple): if isinstance(dtype, tuple):

View file

@ -29,15 +29,15 @@ from abc import ABC
from functools import lru_cache from functools import lru_cache
from typing import Any, Dict, List, Union from typing import Any, Dict, List, Union
from nptyping.base_meta_classes import ContainerMeta from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta
from nptyping.error import InvalidShapeError, NPTypingError from numpydantic.vendor.nptyping.error import InvalidShapeError, NPTypingError
from nptyping.nptyping_type import NPTypingType from numpydantic.vendor.nptyping.nptyping_type import NPTypingType
from nptyping.shape_expression import ( from numpydantic.vendor.nptyping.shape_expression import (
get_dimensions, get_dimensions,
normalize_shape_expression, normalize_shape_expression,
remove_labels, remove_labels,
) )
from nptyping.typing_ import ShapeExpression, ShapeTuple from numpydantic.vendor.nptyping.typing_ import ShapeExpression, ShapeTuple
class ShapeMeta(ContainerMeta, implementation="Shape"): class ShapeMeta(ContainerMeta, implementation="Shape"):

View file

@ -22,25 +22,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
""" """
from nptyping.assert_isinstance import assert_isinstance from numpydantic.vendor.nptyping.assert_isinstance import assert_isinstance
from nptyping.error import ( from numpydantic.vendor.nptyping.error import (
InvalidArgumentsError, InvalidArgumentsError,
InvalidDTypeError, InvalidDTypeError,
InvalidShapeError, InvalidShapeError,
InvalidStructureError, InvalidStructureError,
NPTypingError, NPTypingError,
) )
from nptyping.ndarray import NDArray from numpydantic.vendor.nptyping.ndarray import NDArray
from nptyping.package_info import __version__ from numpydantic.vendor.nptyping.package_info import __version__
from nptyping.pandas_.dataframe import DataFrame from numpydantic.vendor.nptyping.pandas_.dataframe import DataFrame
from nptyping.recarray import RecArray from numpydantic.vendor.nptyping.recarray import RecArray
from nptyping.shape import Shape from numpydantic.vendor.nptyping.shape import Shape
from nptyping.shape_expression import ( from numpydantic.vendor.nptyping.shape_expression import (
normalize_shape_expression, normalize_shape_expression,
validate_shape_expression, validate_shape_expression,
) )
from nptyping.structure import Structure from numpydantic.vendor.nptyping.structure import Structure
from nptyping.typing_ import ( from numpydantic.vendor.nptyping.typing_ import (
Bool, Bool,
Bool8, Bool8,
Byte, Byte,

View file

@ -23,7 +23,8 @@ SOFTWARE.
""" """
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from inspect import FrameInfo from inspect import FrameInfo, getframeinfo
from types import FrameType
from typing import ( from typing import (
Any, Any,
Dict, Dict,
@ -34,7 +35,7 @@ from typing import (
TypeVar, TypeVar,
) )
from nptyping.error import InvalidArgumentsError, NPTypingError from numpydantic.vendor.nptyping.error import InvalidArgumentsError, NPTypingError
_T = TypeVar("_T") _T = TypeVar("_T")
@ -126,10 +127,14 @@ class SubscriptableMeta(ABCMeta):
@abstractmethod @abstractmethod
def _get_item(cls, item: Any) -> Tuple[Any, ...]: ... # pragma: no cover 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 # The magic below makes Python's help function display a meaningful
# text with nptyping types. # 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( def _get_additional_values(
cls, item: Any # pylint: disable=unused-argument cls, item: Any # pylint: disable=unused-argument

View file

@ -27,7 +27,7 @@ from abc import ABC
from typing import Any, Tuple from typing import Any, Tuple
import numpy as np import numpy as np
from nptyping.base_meta_classes import ( from numpydantic.vendor.nptyping.base_meta_classes import (
FinalMeta, FinalMeta,
ImmutableMeta, ImmutableMeta,
InconstructableMeta, InconstructableMeta,
@ -35,13 +35,16 @@ from nptyping.base_meta_classes import (
PrintableMeta, PrintableMeta,
SubscriptableMeta, SubscriptableMeta,
) )
from nptyping.error import InvalidArgumentsError from numpydantic.vendor.nptyping.error import InvalidArgumentsError
from nptyping.nptyping_type import NPTypingType from numpydantic.vendor.nptyping.nptyping_type import NPTypingType
from nptyping.shape import Shape from numpydantic.vendor.nptyping.shape import Shape
from nptyping.shape_expression import check_shape from numpydantic.vendor.nptyping.shape_expression import check_shape
from nptyping.structure import Structure from numpydantic.vendor.nptyping.structure import Structure
from nptyping.structure_expression import check_structure, check_type_names from numpydantic.vendor.nptyping.structure_expression import (
from nptyping.typing_ import ( check_structure,
check_type_names,
)
from numpydantic.vendor.nptyping.typing_ import (
DType, DType,
dtype_per_name, dtype_per_name,
name_per_dtype, name_per_dtype,
@ -67,7 +70,7 @@ class NDArrayMeta(
@property @property
def __module__(cls) -> str: 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, ...]: def _get_item(cls, item: Any) -> Tuple[Any, ...]:
cls._check_item(item) cls._check_item(item)

View file

@ -27,8 +27,8 @@ from abc import ABC
from typing import Any, Tuple from typing import Any, Tuple
import numpy as np import numpy as np
from nptyping import InvalidArgumentsError from numpydantic.vendor.nptyping import InvalidArgumentsError
from nptyping.base_meta_classes import ( from numpydantic.vendor.nptyping.base_meta_classes import (
FinalMeta, FinalMeta,
ImmutableMeta, ImmutableMeta,
InconstructableMeta, InconstructableMeta,
@ -36,11 +36,11 @@ from nptyping.base_meta_classes import (
PrintableMeta, PrintableMeta,
SubscriptableMeta, SubscriptableMeta,
) )
from nptyping.error import DependencyError from numpydantic.vendor.nptyping.error import DependencyError
from nptyping.nptyping_type import NPTypingType from numpydantic.vendor.nptyping.nptyping_type import NPTypingType
from nptyping.pandas_.typing_ import dtype_per_name from numpydantic.vendor.nptyping.pandas_.typing_ import dtype_per_name
from nptyping.structure import Structure from numpydantic.vendor.nptyping.structure import Structure
from nptyping.structure_expression import check_structure from numpydantic.vendor.nptyping.structure_expression import check_structure
try: try:
import pandas as pd import pandas as pd
@ -105,7 +105,7 @@ class DataFrameMeta(
@property @property
def __module__(cls) -> str: 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: def _check_item(cls, item: Any) -> None:
# Check if the item is what we expect and raise if it is not. # Check if the item is what we expect and raise if it is not.

View file

@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
""" """
from nptyping.typing_ import Object from numpydantic.vendor.nptyping.typing_ import Object
from nptyping.typing_ import dtype_per_name as dtype_per_name_default from numpydantic.vendor.nptyping.typing_ import dtype_per_name as dtype_per_name_default
dtype_per_name = { dtype_per_name = {
**dtype_per_name_default, # type: ignore[arg-type] **dtype_per_name_default, # type: ignore[arg-type]

View file

@ -26,10 +26,11 @@ import inspect
from typing import Any, Tuple from typing import Any, Tuple
import numpy as np import numpy as np
from nptyping.error import InvalidArgumentsError
from nptyping.ndarray import NDArray, NDArrayMeta from numpydantic.vendor.nptyping.error import InvalidArgumentsError
from nptyping.structure import Structure from numpydantic.vendor.nptyping.ndarray import NDArray, NDArrayMeta
from nptyping.typing_ import DType from numpydantic.vendor.nptyping.structure import Structure
from numpydantic.vendor.nptyping.typing_ import DType
class RecArrayMeta(NDArrayMeta, implementation="RecArray"): class RecArrayMeta(NDArrayMeta, implementation="RecArray"):
@ -52,7 +53,7 @@ class RecArrayMeta(NDArrayMeta, implementation="RecArray"):
@property @property
def __module__(cls) -> str: 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 def __instancecheck__( # pylint: disable=bad-mcs-method-argument
self, instance: Any self, instance: Any

View file

@ -25,9 +25,9 @@ SOFTWARE.
from abc import ABC from abc import ABC
from typing import Any, Dict from typing import Any, Dict
from nptyping.base_meta_classes import ContainerMeta from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta
from nptyping.nptyping_type import NPTypingType from numpydantic.vendor.nptyping.nptyping_type import NPTypingType
from nptyping.shape_expression import ( from numpydantic.vendor.nptyping.shape_expression import (
get_dimensions, get_dimensions,
normalize_shape_expression, normalize_shape_expression,
remove_labels, remove_labels,

View file

@ -33,8 +33,8 @@ from typing import (
Union, Union,
) )
from nptyping.error import InvalidShapeError from numpydantic.vendor.nptyping.error import InvalidShapeError
from nptyping.typing_ import ShapeExpression, ShapeTuple from numpydantic.vendor.nptyping.typing_ import ShapeExpression, ShapeTuple
if TYPE_CHECKING: if TYPE_CHECKING:
from nptyping.shape import Shape # pragma: no cover from nptyping.shape import Shape # pragma: no cover

View file

@ -29,9 +29,9 @@ from typing import (
List, List,
) )
from nptyping.base_meta_classes import ContainerMeta from numpydantic.vendor.nptyping.base_meta_classes import ContainerMeta
from nptyping.nptyping_type import NPTypingType from numpydantic.vendor.nptyping.nptyping_type import NPTypingType
from nptyping.structure_expression import ( from numpydantic.vendor.nptyping.structure_expression import (
create_name_to_type_dict, create_name_to_type_dict,
normalize_structure_expression, normalize_structure_expression,
validate_structure_expression, validate_structure_expression,

View file

@ -27,9 +27,18 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal # type: ignore[attr-defined,misc,assignment] 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 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: # For MyPy:
Structure = cast(Literal, Structure) # type: ignore[has-type,misc,valid-type] Structure = cast(Literal, Structure) # type: ignore[has-type,misc,valid-type]

View file

@ -38,14 +38,14 @@ from typing import (
) )
import numpy as np import numpy as np
from nptyping.error import InvalidShapeError, InvalidStructureError from numpydantic.vendor.nptyping.error import InvalidShapeError, InvalidStructureError
from nptyping.shape import Shape from numpydantic.vendor.nptyping.shape import Shape
from nptyping.shape_expression import ( from numpydantic.vendor.nptyping.shape_expression import (
check_shape, check_shape,
normalize_shape_expression, normalize_shape_expression,
validate_shape_expression, validate_shape_expression,
) )
from nptyping.typing_ import StructureExpression from numpydantic.vendor.nptyping.typing_ import StructureExpression
if TYPE_CHECKING: if TYPE_CHECKING:
from nptyping.structure import Structure # pragma: no cover from nptyping.structure import Structure # pragma: no cover