Skip to content

Commit

Permalink
Release/2.1.2 (#78)
Browse files Browse the repository at this point in the history
* Fixed bug that ndarrays were considered to be instances of RecArray.

* Version bump.

* Fix for "_DType_co" MyPy complaint.

* Added test to check the version is increased.

* Fix for the install task to install on every environment.

* Moved some requirements from build to qa.

* Updated the constraints

* Added pip upgrade to the install task

* Changed date.

Co-authored-by: Ramon <p8u7wAPC5Pg9HYkkCkzA>
  • Loading branch information
ramonhagenaars committed Jun 8, 2022
1 parent a95dd01 commit 14a6bba
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 168 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 2.1.2 (2022-06-08)

- Fixed bug that caused MyPy to fail with the message: Value of type variable "_DType_co" of "ndarray" cannot be "floating[Any]"

## 2.1.1 (2022-06-01)

- Fixed bug that numpy ndarrays were incorrectly instance checked against `RecArray`.
Expand Down
13 changes: 11 additions & 2 deletions USERDOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,23 @@ Unicode
Str0

```
These are just aliases for `numpy` dtypes.
These are special aliases for `numpy` dtypes.
```python
>>> from nptyping import Int
>>> Int
<class 'numpy.int32'>

```
As a result, you may also provide `numpy` dtypes directly to an `NDArray`.
You may also provide `numpy` dtypes directly to an `NDArray`. This is <strong>not</strong> recommended though, because
MyPy won't accept it.
```python
>>> import numpy as np

>>> NDArray[Any, np.floating]
NDArray[Any, Floating]

```


### Structure expressions
You can denote the structure of a structured array using what we call a **structure expression**. This expression
Expand Down
47 changes: 29 additions & 18 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,93 @@
#
# pip-compile --output-file=constraints.txt './dependencies\build-requirements.txt' './dependencies\qa-requirements.txt' './dependencies\requirements.txt'
#
astroid==2.9.3
astroid==2.11.5
# via pylint
autoflake==1.4
# via -r ./dependencies\qa-requirements.txt
black==22.1.0
beartype==0.10.4 ; python_version >= "3.10"
# via -r ./dependencies\qa-requirements.txt
certifi==2021.10.8
black==22.3.0
# via -r ./dependencies\qa-requirements.txt
certifi==2022.5.18.1
# via requests
charset-normalizer==2.0.12
# via requests
click==8.0.4
click==8.1.3
# via
# black
# pip-tools
codecov==2.1.12
# via -r ./dependencies\build-requirements.txt
# via -r ./dependencies\qa-requirements.txt
colorama==0.4.4
# via
# click
# pylint
coverage==6.3.1
coverage==6.4.1
# via
# -r ./dependencies\qa-requirements.txt
# codecov
dill==0.3.5.1
# via pylint
feedparser==6.0.10
# via -r ./dependencies\qa-requirements.txt
idna==3.3
# via requests
invoke==1.6.0
invoke==1.7.1
# via -r ./dependencies\build-requirements.txt
isort==5.10.1
# via
# -r ./dependencies\qa-requirements.txt
# pylint
lazy-object-proxy==1.7.1
# via astroid
mccabe==0.6.1
mccabe==0.6.0
# via pylint
mypy==0.931
mypy==0.961
# via -r ./dependencies\qa-requirements.txt
mypy-extensions==0.4.3
# via
# black
# mypy
numpy==1.21.5
numpy==1.22.4 ; python_version >= "3.8"
# via -r ./dependencies\requirements.txt
pathspec==0.9.0
# via black
pep517==0.12.0
# via pip-tools
pip-tools==6.5.1
pip-tools==6.6.2
# via -r ./dependencies\build-requirements.txt
platformdirs==2.5.1
platformdirs==2.5.2
# via
# black
# pylint
pyflakes==2.4.0
# via autoflake
pylint==2.12.2
pylint==2.14.1
# via -r ./dependencies\qa-requirements.txt
requests==2.27.1
# via codecov
toml==0.10.2
# via pylint
sgmllib3k==1.0.0
# via feedparser
tomli==2.0.1
# via
# black
# mypy
# pep517
typing-extensions==4.1.1
# pylint
tomlkit==0.11.0
# via pylint
typeguard==2.13.3
# via -r ./dependencies\qa-requirements.txt
typing-extensions==4.2.0
# via mypy
urllib3==1.26.8
urllib3==1.26.9
# via requests
wheel==0.37.1
# via
# -r ./dependencies\qa-requirements.txt
# pip-tools
wrapt==1.13.3
wrapt==1.14.1
# via astroid

# The following packages are considered to be unsafe in a requirements file:
Expand Down
1 change: 0 additions & 1 deletion dependencies/build-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
invoke>=1.6.0
pip-tools>=6.5.0
codecov>=2.1.0
2 changes: 2 additions & 0 deletions dependencies/qa-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
autoflake
black
coverage
codecov>=2.1.0
isort
mypy
pylint
Expand All @@ -9,3 +10,4 @@ wheel
beartype<0.10.0; python_version<'3.10'
beartype>=0.10.0; python_version>='3.10'
typeguard
feedparser
5 changes: 3 additions & 2 deletions dependencies/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy>=1.20.0,<2.0.0
typing_extensions>=4.0.0,<5.0.0; python_version < '3.10'
numpy==1.21.5; python_version<'3.8'
numpy>=1.20.0,<2.0.0; python_version>='3.8'
typing_extensions>=4.0.0,<5.0.0; python_version<'3.10'
2 changes: 1 addition & 1 deletion nptyping/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""
__title__ = "nptyping"
__version__ = "2.1.1"
__version__ = "2.1.2"
__author__ = "Ramon Hagenaars"
__author_email__ = "[email protected]"
__description__ = "Type hints for NumPy."
Expand Down
7 changes: 2 additions & 5 deletions nptyping/structure_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
Dict,
List,
Mapping,
Tuple,
Union,
)

Expand Down Expand Up @@ -77,9 +76,7 @@ def check_structure(
occur in a structure expression.
:return: True if the given dtype is valid with the given target.
"""
fields: Mapping[
str, Union[Tuple[np.dtype[Any], int], Tuple[np.dtype[Any], int, Any]]
] = (structured_dtype.fields or {})
fields: Mapping[str, Any] = structured_dtype.fields or {} # type: ignore[assignment]
for name, dtype_tuple in fields.items():
dtype = dtype_tuple[0]
target_type_name = target.get_type(name)
Expand Down Expand Up @@ -166,7 +163,7 @@ def _validate_structure_expression_contains_no_multiple_field_names(
# Validate that there are not multiple occurrences of the same field names.
matches = re.findall(_REGEX_FIELD, re.sub(r"\s*", "", structure_expression))
field_name_combinations = [match[0].split(":")[0] for match in matches]
field_names = []
field_names: List[str] = []
for field_name_combination in field_name_combinations:
field_name_combination_match = re.match(
_REGEX_FIELD_NAMES_COMBINATION, field_name_combination
Expand Down
128 changes: 64 additions & 64 deletions nptyping/typing_.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,70 +46,70 @@
DType: TypeAlias = Union[np.generic, StructureExpression]
ShapeTuple: TypeAlias = Tuple[int, ...]

Number: TypeAlias = np.number
Bool: TypeAlias = np.bool_
Bool8: TypeAlias = np.bool8
Object: TypeAlias = np.object_
Object0: TypeAlias = np.object0
Datetime64: TypeAlias = np.datetime64
Integer: TypeAlias = np.integer
SignedInteger: TypeAlias = np.signedinteger
Int8: TypeAlias = np.int8
Int16: TypeAlias = np.int16
Int32: TypeAlias = np.int32
Int64: TypeAlias = np.int64
Byte: TypeAlias = np.byte
Short: TypeAlias = np.short
IntC: TypeAlias = np.intc
IntP: TypeAlias = np.intp
Int0: TypeAlias = np.int0
Int: TypeAlias = np.int_
LongLong: TypeAlias = np.longlong
Timedelta64: TypeAlias = np.timedelta64
UnsignedInteger: TypeAlias = np.unsignedinteger
UInt8: TypeAlias = np.uint8
UInt16: TypeAlias = np.uint16
UInt32: TypeAlias = np.uint32
UInt64: TypeAlias = np.uint64
UByte: TypeAlias = np.ubyte
UShort: TypeAlias = np.ushort
UIntC: TypeAlias = np.uintc
UIntP: TypeAlias = np.uintp
UInt0: TypeAlias = np.uint0
UInt: TypeAlias = np.uint
ULongLong: TypeAlias = np.ulonglong
Inexact: TypeAlias = np.inexact
Floating: TypeAlias = np.floating
Float16: TypeAlias = np.float16
Float32: TypeAlias = np.float32
Float64: TypeAlias = np.float64
Half: TypeAlias = np.half
Single: TypeAlias = np.single
Double: TypeAlias = np.double
Float: TypeAlias = np.float_
LongDouble: TypeAlias = np.longdouble
LongFloat: TypeAlias = np.longfloat
ComplexFloating: TypeAlias = np.complexfloating
Complex64: TypeAlias = np.complex64
Complex128: TypeAlias = np.complex128
CSingle: TypeAlias = np.csingle
SingleComplex: TypeAlias = np.singlecomplex
CDouble: TypeAlias = np.cdouble
Complex: TypeAlias = np.complex_
CFloat: TypeAlias = np.cfloat
CLongDouble: TypeAlias = np.clongdouble
CLongFloat: TypeAlias = np.clongfloat
LongComplex: TypeAlias = np.longcomplex
Flexible: TypeAlias = np.flexible
Void: TypeAlias = np.void
Void0: TypeAlias = np.void0
Character: TypeAlias = np.character
Bytes: TypeAlias = np.bytes_
Str: TypeAlias = np.str_
String: TypeAlias = np.string_
Bytes0: TypeAlias = np.bytes0
Unicode: TypeAlias = np.unicode_
Str0: TypeAlias = np.str0
Number = np.number
Bool = np.bool_
Bool8 = np.bool8
Object = np.object_
Object0 = np.object0
Datetime64 = np.datetime64
Integer = np.integer
SignedInteger = np.signedinteger
Int8 = np.int8
Int16 = np.int16
Int32 = np.int32
Int64 = np.int64
Byte = np.byte
Short = np.short
IntC = np.intc
IntP = np.intp
Int0 = np.int0
Int = np.int_
LongLong = np.longlong
Timedelta64 = np.timedelta64
UnsignedInteger = np.unsignedinteger
UInt8 = np.uint8
UInt16 = np.uint16
UInt32 = np.uint32
UInt64 = np.uint64
UByte = np.ubyte
UShort = np.ushort
UIntC = np.uintc
UIntP = np.uintp
UInt0 = np.uint0
UInt = np.uint
ULongLong = np.ulonglong
Inexact = np.inexact
Floating = np.floating
Float16 = np.float16
Float32 = np.float32
Float64 = np.float64
Half = np.half
Single = np.single
Double = np.double
Float = np.float_
LongDouble = np.longdouble
LongFloat = np.longfloat
ComplexFloating = np.complexfloating
Complex64 = np.complex64
Complex128 = np.complex128
CSingle = np.csingle
SingleComplex = np.singlecomplex
CDouble = np.cdouble
Complex = np.complex_
CFloat = np.cfloat
CLongDouble = np.clongdouble
CLongFloat = np.clongfloat
LongComplex = np.longcomplex
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

dtypes = [
(Number, "Number"),
Expand Down
Loading

0 comments on commit 14a6bba

Please sign in to comment.