You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm afraid that use of a typevar here wouldn't quite solve the issue:
What's going on here is that np.array_split() calls np.swapaxes() under the hood, which in turn calls pd.DataFrame.swapaxes() via an intermediate getattr() call, which in turn is finally responsible for returning the dataframe. Properly typing this entire protocol chain would, at best, be non-trivial (my memory is a bit vague on the subject, but I recall some past issues in mypy related to overloaded protocols and typevars in the past. Not sure to what degree this is still relevant though).
To make things even more "interesting" pd.DataFrame.swapaxes() seems to be deprecated ever since pandas 2.1.0, so even during runtime the code snippet you posted above will return two numpy arrays in the future unless pandas implements something like the __array_function__ protocol.
Proposed new feature or change:
Hi all,
Consider the following code (numpy v1.23.0, mypy v0.982; I checked and the signature of the function hasn't changed in numpy v.1.24.0):
However, when mypy is run on this code with
reveal_type(batch)
instead ofprint(...)
, we get:Revealed type is "numpy.ndarray[Any, numpy.dtype[Any]]"
.Has this been thought of in the past? I guess the best solution would be to introduce
TypeVar
somewhere, but it might be not so obvious?The text was updated successfully, but these errors were encountered: