-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid a couple of warnings in polyfit
#8939
Conversation
The `copy` kwarg appears to only exist in `numpy>=2`.
xarray/namedarray/_typing.py
Outdated
def __array__(self, dtype: None = ..., /) -> np.ndarray[Any, _DType_co]: ... | ||
def __array__( | ||
self, dtype: None = ..., copy: None = ..., / | ||
) -> np.ndarray[Any, _DType_co]: ... | ||
|
||
@overload | ||
def __array__(self, dtype: _DType, /) -> np.ndarray[Any, _DType]: ... | ||
def __array__(self, dtype: _DType, copy: bool, /) -> np.ndarray[Any, _DType]: ... | ||
|
||
def __array__( | ||
self, dtype: _DType | None = ..., / | ||
self, dtype: _DType | None = ..., copy: bool | None = None, / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Illviljan (or anyone else), I might need some help to get the typing right... basically, __array__
is supposed to have a new kwarg, copy
, which is either a bool
or None
.
Edit: my best guess, adding copy: bool | None = None
to the overloads, didn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's more places with __array__
to fix:
xarray/core/indexing.py:472: note: Got:
xarray/core/indexing.py:472: note: @overload
xarray/core/indexing.py:472: note: def __array__(self, None = ..., /) -> ndarray[Any, dtype[generic]]
xarray/core/indexing.py:472: note: @overload
xarray/core/indexing.py:472: note: def [_DType <: dtype[Any]] __array__(self, _DType, /) -> ndarray[Any, _DType]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpy's type hints:
@overload
def __array__(
self, dtype: None = ..., /, *, copy: None | bool = ...
) -> ndarray[Any, _DType_co]: ...
@overload
def __array__(
self, dtype: _DType, /, *, copy: None | bool = ...
) -> ndarray[Any, _DType]: ...
I've removed all the forwarding of If we can get the type checking to pass this should be ready for reviews and merging. |
okay, so I believe I've fixed most of the issues. However, since the |
Definitely the correct call imo! But can we ensure the |
The issue here is that this is the upcoming In general, though, I think we need to figure out what to do with backwards compatibility in typing. |
Would it be reasonable to lock the mypy tests at numpy <2, and then when numpy>=2 is released, we do a single PR which upgrades our mypy tests to numpy>=2? And then we can merge this PR then? I think trying to fix mypy for multiple dependency versions might be too hard (I already find it difficult for a single version!) |
probably. However, I don't know enough about typing to get that to work. So if anyone has ideas, feel free to push to this PR. |
(OK — just tbc — my suggestion is not to change the typing. But instead to lock the CI dependencies for mypy at numpy <2 until numpy 2 is released, at which point we lock to numpy > 2. And then to merge anything that requires numpy 2 typing, which may include this PR...) |
you mean, let's try reverting the typing and see if everything passes? I remember changing the typing because the CI failed, so as far as I can tell (with my limited knowledge of typing) at least some changes are necessary. |
I'm saying that if the typing is proving difficult, we should abandon the goal of mypy passing with both numpy 1 and numpy 2 as dependencies. For tests, we should really try to pass with both numpy 1 & 2, because we can easily have if/else branches, and it affects people running the code. But with typing it's both more difficult and less useful... |
makes sense. What I'm saying, though, is that without any changes at all to the typing, |
Either our trusty |
I don't know enough about typing to ignore typing issues within a protocol, so that was the only way I could figure out how to get this PR unstuck. Once we know what to do here, we can remove the ignore in a new PR.
Since I really have no idea how to fix the typing issues (ignore comments won't work because we usually don't call the protocol ourselves), I've decided to ignore the warning in all our CI for now, and punt the change to the signature in most cases to a future PR. Hopefully this allows us to move forward with this PR. |
looks like this works now? Should we merge? |
Thanks for working through this @keewis Can you open an issue please? |
numpy.core.finfo
withnumpy.finfo
dtype
andcopy
parameters to all definitions of__array__