Skip to content
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

Verbose error handling for non-valid duckarrays #9314

Conversation

Illviljan
Copy link
Contributor

@Illviljan Illviljan commented Aug 5, 2024

It is rather annoying trying to figure out why some arrays aren't valid duckarrays. This PR logs the missing attributes instead of just saying it isn't valid.

Example:

    def test_duck_array_class_pd_index(self) -> None:
        import pandas as pd

        a: duckarray[Any, Any] = pd.Index([])
        check_duck_array_typevar(a)
FAILED xarray/tests/test_namedarray.py::TestNamedArray::test_pd_index_duckarray - TypeError: a (<class 'pandas.core.indexes.base.Index'>) is not a valid _arrayfunction or _arrayapi. Missing following attrs:
_arrayfunction - {'imag', '__array_function__', 'real'}
_arrayapi - {'__array_namespace__'}

Further reading: python/cpython#104873

@Illviljan Illviljan marked this pull request as ready for review August 5, 2024 15:03
@Illviljan
Copy link
Contributor Author

The mypy CI is uninstalling numpy 2.0.1 and installing numpy 1.26 instead for some reason, anyone know why?

Run python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report xarray/
Collecting pandas-stubs
  Downloading pandas_stubs-2.2.2.240805-py3-none-any.whl.metadata (10 kB)
Collecting types-PyYAML
  Downloading types_PyYAML-6.0.12.20240724-py3-none-any.whl.metadata (1.6 kB)
Collecting types-Pygments
  Downloading types_Pygments-2.18.0.20240506-py3-none-any.whl.metadata (1.8 kB)
Collecting types-cffi
  Downloading types_cffi-1.16.0.20240331-py3-none-any.whl.metadata (1.6 kB)
Collecting types-colorama
  Downloading types_colorama-0.4.15.20240311-py3-none-any.whl.metadata (1.6 kB)
Collecting types-psutil
  Downloading types_psutil-6.0.0.20240621-py3-none-any.whl.metadata (1.6 kB)
Collecting types-python-dateutil
  Downloading types_python_dateutil-2.9.0.20240316-py3-none-any.whl.metadata (1.8 kB)
Collecting types-pytz
  Downloading types_pytz-2024.1.0.20240417-py3-none-any.whl.metadata (1.5 kB)
Collecting types-requests
  Downloading types_requests-2.32.0.20240712-py3-none-any.whl.metadata (1.9 kB)
Collecting types-tqdm
  Downloading types_tqdm-4.66.0.20240417-py3-none-any.whl.metadata (1.5 kB)
Collecting numpy<2.0.0,>=1.23.5 (from pandas-stubs)
  Downloading numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
Collecting types-docutils (from types-Pygments)
  Downloading types_docutils-0.21.0.20240724-py3-none-any.whl.metadata (1.9 kB)
Collecting types-setuptools (from types-Pygments)
  Downloading types_setuptools-71.1.0.20240726-py3-none-any.whl.metadata (1.8 kB)
Requirement already satisfied: urllib3>=2 in /home/runner/micromamba/envs/xarray-tests/lib/python3.11/site-packages (from types-requests) (2.2.2)
Downloading pandas_stubs-2.2.2.240805-py3-none-any.whl (157 kB)
Downloading types_PyYAML-6.0.12.20240724-py3-none-any.whl (15 kB)
Downloading types_Pygments-2.18.0.20240506-py3-none-any.whl (20 kB)
Downloading types_cffi-1.16.0.20240331-py3-none-any.whl (14 kB)
Downloading types_colorama-0.4.15.20240311-py3-none-any.whl (5.8 kB)
Downloading types_psutil-6.0.0.20240621-py3-none-any.whl (18 kB)
Downloading types_python_dateutil-2.9.0.20240316-py3-none-any.whl (9.7 kB)
Downloading types_pytz-2024.1.0.20240417-py3-none-any.whl (5.2 kB)
Downloading types_requests-2.32.0.20240712-py3-none-any.whl (15 kB)
Downloading types_tqdm-4.66.0.20240417-py3-none-any.whl (19 kB)
Downloading numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB)
25l   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/18.3 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.3/18.3 MB 178.7 MB/s eta 0:00:00
25hDownloading types_docutils-0.21.0.20240724-py3-none-any.whl (27 kB)
Downloading types_setuptools-71.1.0.20240726-py3-none-any.whl (64 kB)
Installing collected packages: types-tqdm, types-setuptools, types-requests, types-PyYAML, types-pytz, types-python-dateutil, types-psutil, types-docutils, types-colorama, numpy, types-Pygments, types-cffi, pandas-stubs
  Attempting uninstall: numpy
    Found existing installation: numpy 2.0.1
    Uninstalling numpy-2.0.1:
      Successfully uninstalled numpy-2.0.1
Successfully installed numpy-1.26.4 pandas-stubs-2.2.2.240805 types-PyYAML-6.0.12.20240724 types-Pygments-2.18.0.20240506 types-cffi-1.16.0.20240331 types-colorama-0.4.15.20240311 types-docutils-0.21.0.20240724 types-psutil-6.0.0.20240621 types-python-dateutil-2.9.0.20240316 types-pytz-2024.1.0.20240417 types-requests-2.32.0.20240712 types-setuptools-71.1.0.20240726 types-tqdm-4.66.0.20240417

@Illviljan
Copy link
Contributor Author

Illviljan commented Aug 5, 2024

pandas-stubs forces numpy <2.0.0 now: pandas-dev/pandas-stubs#943
I'm not sure how to deal with this.

@max-sixty
Copy link
Collaborator

Very nice!

@TomNicholas TomNicholas added topic-error reporting topic-arrays related to flexible array support array API standard Support for the Python array API standard labels Aug 6, 2024
@Illviljan Illviljan added the plan to merge Final call for comments label Aug 6, 2024
@Illviljan Illviljan merged commit b22c429 into pydata:main Aug 8, 2024
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array API standard Support for the Python array API standard plan to merge Final call for comments topic-arrays related to flexible array support topic-error reporting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants