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

beartype and typeguard don't like the NDArray repr #115

Open
bnavigator opened this issue Feb 16, 2024 · 2 comments
Open

beartype and typeguard don't like the NDArray repr #115

bnavigator opened this issue Feb 16, 2024 · 2 comments

Comments

@bnavigator
Copy link

Testing with beartype 0.17 produces the following output:

[    8s] ======================================================================
[    8s] ERROR: tests.test_beartype (unittest.loader._FailedTest)
...
[    8s] beartype.roar.BeartypeDecorHintPep604Exception: Type hint NDArray[Shape['2, 2'], Float] inconsistent with respect to repr() strings. Since @beartype requires consistency between type hints and repr() strings, this hint is unsupported by @beartype. Consider reporting this issue to the third-party developer implementing this hint: e.g.,
[    8s]        >>> repr(NDArray[Shape['2, 2'], Float])
[    8s]        NDArray[Shape['2, 2'], Float]  # <-- this is fine
[    8s]        >>> repr(NDArray[Shape['2, 2'], Float] | int)
[    8s]        nptyping.ndarray.NDArray | int  # <-- *THIS IS REALLY SUPER BAD*
[    8s] 
[    8s]        # Ideally, that output should instead resemble:
[    8s]        >>> repr(NDArray[Shape['2, 2'], Float] | int)
[    8s]        NDArray[Shape['2, 2'], Float] | int  # <-- what @beartype wants!
@bnavigator
Copy link
Author

And with typeguard:

[    6s] ======================================================================
[    6s] ERROR: test_success (tests.test_typeguard.TypeguardTest)
[    6s] ----------------------------------------------------------------------
[    6s] Traceback (most recent call last):
[    6s]   File "/home/abuild/rpmbuild/BUILD/nptyping-2.5.0/tests/test_typeguard.py", line 24, in test_success
[    6s]     fun(np.random.randn(2, 2))
[    6s]   File "/home/abuild/rpmbuild/BUILD/nptyping-2.5.0/tests/test_typeguard.py", line 14, in fun
[    6s]     def fun(_: NDArray[Shape["2, 2"], Float]) -> None:
[    6s]   File "/home/abuild/rpmbuild/BUILD/nptyping-2.5.0/nptyping/base_meta_classes.py", line 145, in __getitem__
[    6s]     args = cls._get_item(item)
[    6s]   File "/home/abuild/rpmbuild/BUILD/nptyping-2.5.0/nptyping/base_meta_classes.py", line 213, in _get_item
[    6s]     raise InvalidArgumentsError(
[    6s] nptyping.error.InvalidArgumentsError: Unexpected argument of type <class 'tuple'>, expecting a string.
[    6s] 
[    6s] ----------------------------------------------------------------------

@bnavigator bnavigator changed the title test_beartype fails beartype and typeguard don't like the NDArray repr Feb 16, 2024
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Feb 20, 2024
https://build.opensuse.org/request/show/1147711
by user mcepl + anag+factory
- Did the upstream just released different tarball with the same
  version number? Yes, they did!
- Rebased patches
- Update to 2.5.0
  * Added the column wildcard in structure expressions to allow
    expressing 'a structure with at least ...'.
  * Fixed the help text for functions that use nptyping types as
    hints.
  * Fixed the distribution of dataframe.pyi that was missing.
  * Fixed the sdist to include tests and dependencies.
- Fix the test suite.
  * The -k parameter for unittests does not know negative patterns
  * Don't test with beartype and typeguard:
    gh#ramonhagenaars/nptyping#115
  * Drop skip-pyright-tests.patch, delete file instead
  * Drop skip_pandas.patch.
@Danguilhen
Copy link

Hello, I have the same problem.
Beartype is testing that PEP 604 is respected this way:
repr(your_nptyping_type | int) == "your_nptyping_type | 1"
The result is different because NDArrayMeta class doesn't have an or dunder method. Btw, the equivalent need to be done for for the DataFrame meta class I guess.
I think that adding one would solve the issue. However, it looks like that nptyping is not maintained anymore, no pull request accepted or commit made since a year. It would be sad to loose such a great tool!

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Jul 10, 2024
https://build.opensuse.org/request/show/1147711
by user mcepl + anag+factory
- Did the upstream just released different tarball with the same
  version number? Yes, they did!
- Rebased patches
- Update to 2.5.0
  * Added the column wildcard in structure expressions to allow
    expressing 'a structure with at least ...'.
  * Fixed the help text for functions that use nptyping types as
    hints.
  * Fixed the distribution of dataframe.pyi that was missing.
  * Fixed the sdist to include tests and dependencies.
- Fix the test suite.
  * The -k parameter for unittests does not know negative patterns
  * Don't test with beartype and typeguard:
    gh#ramonhagenaars/nptyping#115
  * Drop skip-pyright-tests.patch, delete file instead
  * Drop skip_pandas.patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants