-
-
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
Enable pandas type checking #9213
Conversation
It seems that mypy is now resolving the operators more precisely and also it seems that this causes some issues with the current implementation. It looks like we have to completely rework them... :/ |
After some debugging I noticed that DatasetGroupby + Dataset-subclass will return Dataset and not Dataset-subclass. I think refactoring the code to actually return the subclass is blocked by the Coordinates refactor... |
For the pandas items or for all? 🫨 FWIW IIRC the latest mypy fails on |
I remember hitting similar things in the past. Ideally we'd return the subclass; but to the extent we don't I would heavily deprioritize any big effort to change the typing to state we return |
I think I have fixed all mypy issues related to pandas.
I though of quickly fixing these issues here as well, turns out not to be so easy... |
Issue seems to be in try:
from dask.array import Array as DaskArray
except ImportError:
DaskArray = np.ndarray Somehow that gets evaluated to Any, which in turn makes mypy think that If I try to recreate this locally, I don't get Any, so no idea what is going on there... Done for today, lets see how one solves this issue. |
After hours of trying to figure out what is going on, I am close to giving up :/ |
That doesn't sound fun...
Where are the errors from |
As I was saying some comments up, the mypy errors are the ones in _typed_ops. But these are only a symptom not the root of the error... Mainly: |
Something does seem confusing with One thing that does seem to fix almost all errors is just excluding diff --git a/xarray/core/types.py b/xarray/core/types.py
index 20d94de5..5b231780 100644
--- a/xarray/core/types.py
+++ b/xarray/core/types.py
@@ -178,7 +178,8 @@ def copy(
T_ExtensionArray = TypeVar("T_ExtensionArray", bound=pd.api.extensions.ExtensionArray)
-ScalarOrArray = Union["ArrayLike", np.generic, np.ndarray, "DaskArray"]
+# ScalarOrArray = Union[ArrayLike, np.generic, np.ndarray, DaskArray]
+ScalarOrArray = Union[ArrayLike, np.generic, np.ndarray]
VarCompatible = Union["Variable", "ScalarOrArray"]
DaCompatible = Union["DataArray", "VarCompatible"]
DsCompatible = Union["Dataset", "DaCompatible"] FWIW I also get weirdness around using |
@max-sixty thank you! That was the solution, and it does not even matter, because a |
remaining mypy errors are from numpy2, see #9231 |
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.
Very impressive @headtr1ck ! Big lift!
Force-merged since the auto-merge won't work till mypy on main is fixed. |
* main: Enable pandas type checking (pydata#9213) Per-variable specification of boolean parameters in open_dataset (pydata#9218) test push Added a space to the documentation (pydata#9247) Fix typing for test_plot.py (pydata#9234) Allow mypy to run in vscode (pydata#9239) Revert "Test main push" Test main push Revert "Update _typing.py" Update _typing.py Add a `.drop_attrs` method (pydata#8258)
* main: add backend intro and how-to diagram (#9175) Fix copybutton for multi line examples in double digit ipython cells (#9264) Update signature for _arrayfunction.__array__ (#9237) Add encode_cf_datetime benchmark (#9262) groupby, resample: Deprecate some positional args (#9236) Delete ``base`` and ``loffset`` parameters to resample (#9233) Update dropna docstring (#9257) Grouper, Resampler as public api (#8840) Fix mypy on main (#9252) fix fallback isdtype method (#9250) Enable pandas type checking (#9213) Per-variable specification of boolean parameters in open_dataset (#9218) test push Added a space to the documentation (#9247) Fix typing for test_plot.py (#9234)
* main: (54 commits) Adding `open_datatree` backend-specific keyword arguments (#9199) [pre-commit.ci] pre-commit autoupdate (#9202) Restore ability to specify _FillValue as Python native integers (#9258) add backend intro and how-to diagram (#9175) Fix copybutton for multi line examples in double digit ipython cells (#9264) Update signature for _arrayfunction.__array__ (#9237) Add encode_cf_datetime benchmark (#9262) groupby, resample: Deprecate some positional args (#9236) Delete ``base`` and ``loffset`` parameters to resample (#9233) Update dropna docstring (#9257) Grouper, Resampler as public api (#8840) Fix mypy on main (#9252) fix fallback isdtype method (#9250) Enable pandas type checking (#9213) Per-variable specification of boolean parameters in open_dataset (#9218) test push Added a space to the documentation (#9247) Fix typing for test_plot.py (#9234) Allow mypy to run in vscode (#9239) Revert "Test main push" ...
…monotonic-variable * main: (995 commits) Adding `open_datatree` backend-specific keyword arguments (pydata#9199) [pre-commit.ci] pre-commit autoupdate (pydata#9202) Restore ability to specify _FillValue as Python native integers (pydata#9258) add backend intro and how-to diagram (pydata#9175) Fix copybutton for multi line examples in double digit ipython cells (pydata#9264) Update signature for _arrayfunction.__array__ (pydata#9237) Add encode_cf_datetime benchmark (pydata#9262) groupby, resample: Deprecate some positional args (pydata#9236) Delete ``base`` and ``loffset`` parameters to resample (pydata#9233) Update dropna docstring (pydata#9257) Grouper, Resampler as public api (pydata#8840) Fix mypy on main (pydata#9252) fix fallback isdtype method (pydata#9250) Enable pandas type checking (pydata#9213) Per-variable specification of boolean parameters in open_dataset (pydata#9218) test push Added a space to the documentation (pydata#9247) Fix typing for test_plot.py (pydata#9234) Allow mypy to run in vscode (pydata#9239) Revert "Test main push" ...
Since pandas-stubs is making good progress, I would say it is slowly advantageous to enable type checking for it.
About 200 mypy errors have to be fixed....
whats-new.rst