update old numpy dtypes, remove them, lint

This commit is contained in:
sneakers-the-rat 2024-07-31 14:15:24 -07:00
parent 4604e7e7bb
commit 3306703741
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
12 changed files with 33 additions and 52 deletions

View file

@ -101,6 +101,10 @@ select = [
"I",
# annotations
"ANN",
# perf
"PERF",
# numpy
"NPY",
## ----------
# pydocstyle
# undocumented public objects

View file

@ -69,9 +69,7 @@ Half = np.half
Single = np.single
Double = np.double
LongDouble = np.longdouble
LongFloat = np.longfloat
Float = (
np.float_,
np.float16,
np.float32,
np.float64,
@ -84,32 +82,24 @@ ComplexFloating = np.complexfloating
Complex64 = np.complex64
Complex128 = np.complex128
CSingle = np.csingle
SingleComplex = np.singlecomplex
CDouble = np.cdouble
CFloat = np.cfloat
CLongDouble = np.clongdouble
CLongFloat = np.clongfloat
Complex = (
np.complex_,
np.complexfloating,
np.complex64,
np.complex128,
np.csingle,
np.singlecomplex,
np.cdouble,
np.cfloat,
np.clongdouble,
np.clongfloat,
)
LongComplex = np.longcomplex
Flexible = np.flexible
Void = np.void
Character = np.character
Bytes = np.bytes_
Str = np.str_
String = np.string_
Unicode = np.unicode_
String = np.str_
Unicode = np.str_
Number = tuple(
[

View file

@ -144,9 +144,9 @@ class VideoProxy:
elif isinstance(item, slice):
# slice of frames
item = self._complete_slice(item)
frames = []
for i in range(item.start, item.stop, item.step):
frames.append(self._get_frame(i))
frames = [
self._get_frame(i) for i in range(item.start, item.stop, item.step)
]
return np.stack(frames)
else:
# slices are passed as tuples

View file

@ -21,7 +21,7 @@ np_to_python = {
**{n: int for n in dt.Integer},
**{n: float for n in dt.Float},
**{n: complex for n in dt.Complex},
**{n: str for n in (np.character, np.str_, np.string_, np.unicode_)},
**{n: str for n in (np.character, np.str_, np.bytes_, np.str_)},
}
"""Map from python types to numpy"""

View file

@ -16,14 +16,6 @@ Extension of nptyping NDArray for pydantic that allows for JSON-Schema serializa
from typing import TYPE_CHECKING, Any, Tuple
import numpy as np
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
from pydantic_core import core_schema
@ -38,6 +30,14 @@ from numpydantic.schema import (
make_json_schema,
)
from numpydantic.types import DtypeType, ShapeType
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,
)
if TYPE_CHECKING: # pragma: no cover
from nptyping.base_meta_classes import SubscriptableMeta

View file

@ -7,7 +7,6 @@ import hashlib
import json
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
from numpydantic.vendor.nptyping.structure import StructureMeta
import numpy as np
from pydantic import SerializationInfo
from pydantic_core import CoreSchema, core_schema
@ -17,6 +16,7 @@ from numpydantic import dtype as dt
from numpydantic.interface import Interface
from numpydantic.maps import np_to_python
from numpydantic.types import DtypeType, NDArrayType, ShapeType
from numpydantic.vendor.nptyping.structure import StructureMeta
if TYPE_CHECKING:
from numpydantic import Shape

View file

@ -8,7 +8,7 @@ Note that these are types as in python typing types, not classes.
from typing import Any, Protocol, Tuple, Union, runtime_checkable
from nptyping import DType
from numpydantic.vendor.nptyping import DType
ShapeType = Union[Tuple[int, ...], Any]
DtypeType = Union[str, type, Any, DType]

View file

@ -23,12 +23,11 @@ SOFTWARE.
"""
from abc import ABCMeta, abstractmethod
from inspect import FrameInfo, getframeinfo
from inspect import getframeinfo
from types import FrameType
from typing import (
Any,
Dict,
List,
Optional,
Set,
Tuple,

View file

@ -27,6 +27,7 @@ from abc import ABC
from typing import Any, Tuple
import numpy as np
from numpydantic.vendor.nptyping.base_meta_classes import (
FinalMeta,
ImmutableMeta,

View file

@ -27,6 +27,7 @@ from abc import ABC
from typing import Any, Tuple
import numpy as np
from numpydantic.vendor.nptyping import InvalidArgumentsError
from numpydantic.vendor.nptyping.base_meta_classes import (
FinalMeta,

View file

@ -38,6 +38,7 @@ from typing import (
)
import numpy as np
from numpydantic.vendor.nptyping.error import InvalidShapeError, InvalidStructureError
from numpydantic.vendor.nptyping.shape import Shape
from numpydantic.vendor.nptyping.shape_expression import (

View file

@ -22,7 +22,6 @@ 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,
@ -38,10 +37,8 @@ ShapeTuple: TypeAlias = Tuple[int, ...]
Number = np.number
Bool = np.bool_
Bool8 = np.bool8
Obj = np.object_ # Obj is a common abbreviation and should be usable.
Object = np.object_
Object0 = np.object0
Datetime64 = np.datetime64
Integer = np.integer
SignedInteger = np.signedinteger
@ -53,7 +50,6 @@ Byte = np.byte
Short = np.short
IntC = np.intc
IntP = np.intp
Int0 = np.int0
Int = np.integer # Int should translate to the "generic" int type.
Int_ = np.int_
LongLong = np.longlong
@ -67,7 +63,6 @@ UByte = np.ubyte
UShort = np.ushort
UIntC = np.uintc
UIntP = np.uintp
UInt0 = np.uint0
UInt = np.uint
ULongLong = np.ulonglong
Inexact = np.inexact
@ -78,38 +73,33 @@ Float64 = np.float64
Half = np.half
Single = np.single
Double = np.double
Float = np.float_
Float = np.float64
LongDouble = np.longdouble
LongFloat = np.longfloat
LongFloat = np.longdouble
ComplexFloating = np.complexfloating
Complex64 = np.complex64
Complex128 = np.complex128
CSingle = np.csingle
SingleComplex = np.singlecomplex
SingleComplex = np.complex64
CDouble = np.cdouble
Complex = np.complex_
CFloat = np.cfloat
Complex = np.complex128
CFloat = np.complex128
CLongDouble = np.clongdouble
CLongFloat = np.clongfloat
LongComplex = np.longcomplex
CLongFloat = np.clongdouble
LongComplex = np.clongdouble
Flexible = np.flexible
Void = np.void
Void0 = np.void0
Character = np.character
Bytes = np.bytes_
Str = np.str_
String = np.string_
Bytes0 = np.bytes0
Unicode = np.unicode_
Str0 = np.str0
String = np.str_
Unicode = np.str_
dtypes = [
(Number, "Number"),
(Bool, "Bool"),
(Bool8, "Bool8"),
(Obj, "Obj"),
(Object, "Object"),
(Object0, "Object0"),
(Datetime64, "Datetime64"),
(Integer, "Integer"),
(SignedInteger, "SignedInteger"),
@ -121,7 +111,6 @@ dtypes = [
(Short, "Short"),
(IntC, "IntC"),
(IntP, "IntP"),
(Int0, "Int0"),
(Int, "Int"),
(LongLong, "LongLong"),
(Timedelta64, "Timedelta64"),
@ -134,7 +123,6 @@ dtypes = [
(UShort, "UShort"),
(UIntC, "UIntC"),
(UIntP, "UIntP"),
(UInt0, "UInt0"),
(UInt, "UInt"),
(ULongLong, "ULongLong"),
(Inexact, "Inexact"),
@ -161,14 +149,11 @@ dtypes = [
(LongComplex, "LongComplex"),
(Flexible, "Flexible"),
(Void, "Void"),
(Void0, "Void0"),
(Character, "Character"),
(Bytes, "Bytes"),
(String, "String"),
(Str, "Str"),
(Bytes0, "Bytes0"),
(Unicode, "Unicode"),
(Str0, "Str0"),
]
name_per_dtype = dict(dtypes)