Why does NDArray[Any] not work anymore?
Closed this issue · 3 comments
cmacdonald commented
[/usr/local/lib/python3.7/dist-packages/pyterrier/apply.py](https://localhost:8080/#) in <module>()
79 return ApplyDocumentScoringTransformer(fn, *args, **kwargs)
80
---> 81 def doc_features(fn : Callable[..., NDArray[Any]], *args, **kwargs) -> Transformer:
82 """
83 Create a transformer that takes as input a ranked documents dataframe, and applies the supplied function to each document to compute feature scores.
[/usr/local/lib/python3.7/dist-packages/nptyping/ndarray.py](https://localhost:8080/#) in __getitem__(cls, item)
70 raise NPTypingError(f"Type {cls} is already parameterized")
71 if not isinstance(item, tuple):
---> 72 raise InvalidArgumentsError(f"Unexpected argument of type {type(item)}")
73 shape_expression, dtype = _get_from_tuple(item)
74 validate_dtype(dtype)
InvalidArgumentsError: Unexpected argument of type <class 'typing._SpecialForm'>
That code worked fine on previous nptyping
ramonhagenaars commented
The interface of nptyping.NDArray
has changed per 2.0.0
into NDArray[<shape expression, <dtype>]
.
There now are 4 ways to annotate an "any array":
# Option 1:
arr1: np.ndarray # Not MyPy-friendly
# Option 2:
arr2: NDArray # Not MyPy-friendly
# Option 3:
arr3: NDArray[Any, Any]
# Option 4:
arr4: NDArray[Shape["*, ..."], Any]
I'd recommend to use option 3 or 4.
cmacdonald commented
Perhaps a warning in the last 1.x release would have given a warning rather than breaking dependent software.
ramonhagenaars commented