diff options
author | Geoffrey Gunter <12984092+gmgunter@users.noreply.github.com> | 2022-03-14 11:43:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 11:43:44 -0700 |
commit | 71e7620711d6ff8cb838bdffb5e91cdd25497dba (patch) | |
tree | 70b46073760f6cd978909afd25d87158622fda63 | |
parent | fc9044863d270ab4047b6a13b55278bdf31f680c (diff) | |
download | numpy-71e7620711d6ff8cb838bdffb5e91cdd25497dba.tar.gz |
ENH: Add 'ulong' to sctypeDict (#21151)
* ENH: Add 'ulong' to sctypeDict
Closes #21063
* TST: Add a test for np.dtype("ulong")
* REV: Don't add new attribute np.ulong
-rw-r--r-- | numpy/core/_type_aliases.py | 11 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 5 | ||||
-rw-r--r-- | numpy/core/tests/test_numerictypes.py | 7 | ||||
-rw-r--r-- | numpy/typing/_char_codes.py | 2 |
4 files changed, 23 insertions, 2 deletions
diff --git a/numpy/core/_type_aliases.py b/numpy/core/_type_aliases.py index 3765a0d34..9b1dcb8cf 100644 --- a/numpy/core/_type_aliases.py +++ b/numpy/core/_type_aliases.py @@ -172,7 +172,7 @@ def _set_up_aliases(): allTypes[alias] = allTypes[t] sctypeDict[alias] = sctypeDict[t] # Remove aliases overriding python types and modules - to_remove = ['ulong', 'object', 'int', 'float', + to_remove = ['object', 'int', 'float', 'complex', 'bool', 'string', 'datetime', 'timedelta', 'bytes', 'str'] @@ -182,6 +182,15 @@ def _set_up_aliases(): del sctypeDict[t] except KeyError: pass + + # Additional aliases in sctypeDict that should not be exposed as attributes + attrs_to_remove = ['ulong'] + + for t in attrs_to_remove: + try: + del allTypes[t] + except KeyError: + pass _set_up_aliases() diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 1a8e747e1..a23840403 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -1381,6 +1381,11 @@ def test_keyword_argument(): assert np.dtype(dtype=np.float64) == np.dtype(np.float64) +def test_ulong_dtype(): + # test for gh-21063 + assert np.dtype("ulong") == np.dtype(np.uint) + + class TestFromDTypeAttribute: def test_simple(self): class dt: diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py index 9cb00342d..73ff4764d 100644 --- a/numpy/core/tests/test_numerictypes.py +++ b/numpy/core/tests/test_numerictypes.py @@ -436,6 +436,13 @@ class TestSctypeDict: assert_(np.sctypeDict['f8'] is not np.longdouble) assert_(np.sctypeDict['c16'] is not np.clongdouble) + def test_ulong(self): + # Test that 'ulong' behaves like 'long'. np.sctypeDict['long'] is an + # alias for np.int_, but np.long is not supported for historical + # reasons (gh-21063) + assert_(np.sctypeDict['ulong'] is np.uint) + assert_(not hasattr(np, 'ulong')) + class TestBitName: def test_abstract(self): diff --git a/numpy/typing/_char_codes.py b/numpy/typing/_char_codes.py index 139471084..f840d17bb 100644 --- a/numpy/typing/_char_codes.py +++ b/numpy/typing/_char_codes.py @@ -30,7 +30,7 @@ _UByteCodes = Literal["ubyte", "B", "=B", "<B", ">B"] _UShortCodes = Literal["ushort", "H", "=H", "<H", ">H"] _UIntCCodes = Literal["uintc", "I", "=I", "<I", ">I"] _UIntPCodes = Literal["uintp", "uint0", "P", "=P", "<P", ">P"] -_UIntCodes = Literal["uint", "L", "=L", "<L", ">L"] +_UIntCodes = Literal["ulong", "uint", "L", "=L", "<L", ">L"] _ULongLongCodes = Literal["ulonglong", "Q", "=Q", "<Q", ">Q"] _HalfCodes = Literal["half", "e", "=e", "<e", ">e"] |