ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
589 stars 30 forks source link

14 test failures for `=nptyping-2.5.0` (`Name "np.bool8" is not defined`) #113

Open TheChymera opened 11 months ago

TheChymera commented 11 months ago

Full build log: https://ppb.chymera.eu/2facbc.log

Example excerpt of failure:

__________________________________________ MyPyDataFrameTest.test_mypy_knows_of_dataframe_methods __________________________________________

self = <tests.pandas_.test_mypy_dataframe.MyPyDataFrameTest testMethod=test_mypy_knows_of_dataframe_methods>

    @skipUnless(7 < sys.version_info.minor, "MyPy does not work with DataFrame on 3.7")
    def test_mypy_knows_of_dataframe_methods(self):
        # If MyPy knows of some arbitrary DataFrame methods, we can assume that
        # code completion works.
        exit_code, stdout, stderr = check_mypy_on_code(
            """
            from typing import Any
            from nptyping import DataFrame

            df: DataFrame[Any]
            df.shape
            df.dtypes
            df.values
            df.boxplot
            df.filter
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/typing_.pyi:50: error: Name "np.bool8" is not defined  [name-defined]
E       nptyping/typing_.pyi:52: error: Name "np.object0" is not defined  [name-defined]
E       nptyping/typing_.pyi:64: error: Name "np.int0" is not defined  [name-defined]
E       nptyping/typing_.pyi:77: error: Name "np.uint0" is not defined  [name-defined]
E       nptyping/typing_.pyi:104: error: Name "np.void0" is not defined  [name-defined]
E       nptyping/typing_.pyi:109: error: Name "np.bytes0" is not defined  [name-defined]
E       nptyping/typing_.pyi:111: error: Name "np.str0" is not defined  [name-defined]
E       /var/tmp/portage/dev-python/nptyping-2.5.0/temp/tmp40dzg4lh/test_file.py:5: error: "DataFrame" expects no type arguments, but 1 given  [type-arg]
E       Found 8 errors in 2 files (checked 1 source file)

exit_code  = 1
self       = <tests.pandas_.test_mypy_dataframe.MyPyDataFrameTest testMethod=test_mypy_knows_of_dataframe_methods>
stderr     = ''
stdout     = ('nptyping/typing_.pyi:50: error: Name "np.bool8" is not defined  '
 '[name-defined]\n'
 'nptyping/typing_.pyi:52: error: Name "np.object0" is not defined  '
 '[name-defined]\n'
 'nptyping/typing_.pyi:64: error: Name "np.int0" is not defined  '
 '[name-defined]\n'
 'nptyping/typing_.pyi:77: error: Name "np.uint0" is not defined  '
 '[name-defined]\n'
 'nptyping/typing_.pyi:104: error: Name "np.void0" is not defined  '
 '[name-defined]\n'
 'nptyping/typing_.pyi:109: error: Name "np.bytes0" is not defined  '
 '[name-defined]\n'
 'nptyping/typing_.pyi:111: error: Name "np.str0" is not defined  '
 '[name-defined]\n'
 '/var/tmp/portage/dev-python/nptyping-2.5.0/temp/tmp40dzg4lh/test_file.py:5: '
 'error: "DataFrame" expects no type arguments, but 1 given  [type-arg]\n'
 'Found 8 errors in 2 files (checked 1 source file)\n')

tests/pandas_/test_mypy_dataframe.py:61: AssertionError

Any ideas what's wrong here? Is it a question of np.bool8 being deprecated in favour of np.bool_?

Apparently the package already uses both 🤔:

decohost /var/tmp/portage/dev-python/nptyping-2.5.0/work/nptyping-2.5.0 # rg np.bool
tests/test_mypy.py
121:            NDArray[Any, np.dtype[np.bool_]]

tests/test_ndarray.py
269:        self.assertIsInstance(np.array([True]), NDArray[Any, np.bool_])

nptyping/typing_.py
50:Bool = np.bool_
51:Bool8 = np.bool8

nptyping/typing_.pyi
49:Bool: TypeAlias = np.dtype[np.bool_]
50:Bool8: TypeAlias = np.dtype[np.bool8]
stonier commented 11 months ago

I just ran into a large list of warnings as well.

Appears to be a few deprecations in Numpy v1.24:

Is it a question of np.bool8 being deprecated in favour of np.bool_

From what I can gather, numpy's dtype needs something not built-in internally, so that's what np.bool_ is for. From a user's point of view, I think we're supposed to be just using bool.

Some enlightening code:

>>> import numpy as np
np>>> np.bool
<type 'bool'>
>>> np.bool is bool
True
>>> np.bool_ is bool
False 
>>> np.ones(2, dtype=bool).dtype
dtype('bool')
>>> np.ones(2, dtype=np.bool_).dtype
dtype('bool')