Uh oh!
There was an error while loading. Please reload this page.
Enable pandas type checking - #9213
Conversation
headtr1ck
commented
Jul 7, 2024
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... :/ |
headtr1ck
commented
Jul 8, 2024
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... |
max-sixty
commented
Jul 8, 2024
For the pandas items or for all? 🫨 FWIW IIRC the latest mypy fails on |
max-sixty
commented
Jul 8, 2024
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 |
headtr1ck
commented
Jul 8, 2024
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... |
headtr1ck
commented
Jul 8, 2024
Issue seems to be in try:
fromdask.arrayimportArrayasDaskArrayexceptImportError:
DaskArray=np.ndarraySomehow 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. |
headtr1ck
commented
Jul 11, 2024
After hours of trying to figure out what is going on, I am close to giving up :/ |
max-sixty
commented
Jul 11, 2024
That doesn't sound fun...
Where are the errors from |
headtr1ck
commented
Jul 12, 2024
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: |
max-sixty
commented
Jul 12, 2024
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 |
headtr1ck
commented
Jul 12, 2024
@max-sixty thank you! That was the solution, and it does not even matter, because a |
headtr1ck
commented
Jul 12, 2024
remaining mypy errors are from numpy2, see #9231 |
max-sixty
left a comment
There was a problem hiding this comment.
Very impressive @headtr1ck ! Big lift!
dcherian
commented
Jul 17, 2024
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" ...
* main: (54 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