-
-
Notifications
You must be signed in to change notification settings - Fork 12.4k
DEP: Remove deprecated numeric types and deprecate remaining #16554
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
Changes from all commits
d4f9fb7
713b906
d5216a1
27e74ce
9e6cfcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Numeric-style type names have been removed from type dictionaries | ||
| ----------------------------------------------------------------- | ||
|
|
||
| To stay in sync with the deprecation for ``np.dtype("Complex64")`` | ||
| and other numeric-style (capital case) types. These were removed | ||
| from ``np.sctypeDict`` and ``np.typeDict``. You should use | ||
| the lower case versions instead. Note that ``"Complex64"`` | ||
| corresponds to ``"complex128"`` and ``"Complex32"`` corresponds | ||
| to ``"complex64"``. The numpy style (new) versions, denote the full | ||
| size and not the size of the real/imaginary part. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Further Numeric Style types Deprecated | ||
| -------------------------------------- | ||
|
|
||
| The remaining numeric-style type codes ``Bytes0``, ``Str0``, | ||
| ``Uint32``, ``Uint64``, and ``Datetime64`` | ||
| have been deprecated. The lower-case variants should be used | ||
| instead. For bytes and string ``"S"`` and ``"U"`` | ||
| are further alternatives. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| * The deprecation of numeric style type-codes ``np.dtype("Complex64")`` | ||
| (with upper case spelling), is expired. ``"Complex64"`` corresponded to | ||
| ``"complex128"`` and ``"Complex32"`` corresponded to ``"complex64"``. | ||
| * The deprecation of ``np.sctypeNA`` and ``np.typeNA`` is expired. Both | ||
| have been removed from the public API. Use ``np.typeDict`` instead. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,40 +11,19 @@ | |
| .. data:: sctypeDict | ||
| Similar to `allTypes`, but maps a broader set of aliases to their types. | ||
|
|
||
| .. data:: sctypeNA | ||
| NumArray-compatible names for the scalar types. Contains not only | ||
| ``name: type`` mappings, but ``char: name`` mappings too. | ||
|
|
||
| .. deprecated:: 1.16 | ||
|
|
||
| .. data:: sctypes | ||
| A dictionary keyed by a "type group" string, providing a list of types | ||
| under that group. | ||
|
|
||
| """ | ||
| import warnings | ||
|
|
||
| from numpy.compat import unicode | ||
| from numpy._globals import VisibleDeprecationWarning | ||
| from numpy.core._string_helpers import english_lower, english_capitalize | ||
| from numpy.core._string_helpers import english_lower | ||
| from numpy.core.multiarray import typeinfo, dtype | ||
| from numpy.core._dtype import _kind_name | ||
|
|
||
|
|
||
| sctypeDict = {} # Contains all leaf-node scalar types with aliases | ||
| class TypeNADict(dict): | ||
| def __getitem__(self, key): | ||
| # 2018-06-24, 1.16 | ||
| warnings.warn('sctypeNA and typeNA will be removed in v1.18 ' | ||
| 'of numpy', VisibleDeprecationWarning, stacklevel=2) | ||
| return dict.__getitem__(self, key) | ||
| def get(self, key, default=None): | ||
| # 2018-06-24, 1.16 | ||
| warnings.warn('sctypeNA and typeNA will be removed in v1.18 ' | ||
| 'of numpy', VisibleDeprecationWarning, stacklevel=2) | ||
| return dict.get(self, key, default) | ||
|
|
||
| sctypeNA = TypeNADict() # Contails all leaf-node types -> numarray type equivalences | ||
| allTypes = {} # Collect the types we will add to the module | ||
|
|
||
|
|
||
|
|
@@ -127,27 +106,24 @@ def _add_aliases(): | |
| if name in ('longdouble', 'clongdouble') and myname in allTypes: | ||
| continue | ||
|
|
||
| base_capitalize = english_capitalize(base) | ||
| if base == 'complex': | ||
| na_name = '%s%d' % (base_capitalize, bit//2) | ||
| elif base == 'bool': | ||
| na_name = base_capitalize | ||
| else: | ||
| na_name = "%s%d" % (base_capitalize, bit) | ||
|
|
||
| allTypes[myname] = info.type | ||
|
|
||
| # add mapping for both the bit name and the numarray name | ||
| sctypeDict[myname] = info.type | ||
| sctypeDict[na_name] = info.type | ||
|
|
||
| # add forward, reverse, and string mapping to numarray | ||
| sctypeNA[na_name] = info.type | ||
| sctypeNA[info.type] = na_name | ||
| sctypeNA[info.char] = na_name | ||
|
|
||
| sctypeDict[char] = info.type | ||
| sctypeNA[char] = na_name | ||
|
|
||
| # Add deprecated numeric-style type aliases manually, at some point | ||
| # we may want to deprecate the lower case "bytes0" version as well. | ||
| for name in ["Bytes0", "Datetime64", "Str0", "Uint32", "Uint64"]: | ||
| if english_lower(name) not in allTypes: | ||
| # Only one of Uint32 or Uint64, aliases of `np.uintp`, was (and is) defined, note that this | ||
| # is not UInt32/UInt64 (capital i), which is removed. | ||
| continue | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if is weird, but it failed tests and I think it is correct... if anyone has a 32bit linux or maybe windows to see that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It now passes tests, is this comment outdated?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I worked around it. But, I now realized on windows we probably had a stray
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. np.typeDict has
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note the 'I' in 'UInt64'
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The capitalized It looks to me like I added this type accidentally as part of giving >>> numpy.__version__
'1.11.0'
>>> sorted(k for k in numpy.typeDict.keys() if isinstance(k, str) and k[0].isupper() and len(k) > 2)
['Bool', 'Complex128', 'Complex32', 'Complex64', 'Datetime64', 'Float128', 'Float16', 'Float32', 'Float64', 'Int16', 'Int32', 'Int64', 'Int8', 'Object0', 'String0', 'Timedelta64', 'UInt16', 'UInt32', 'UInt64', 'UInt8', 'Unicode0', 'Void0']So I think we can just remove this special case?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that makes it more recent. I think we could just remove it, but if we want to get rid of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for reference - the So on 32-bit platforms, there will be a Let's either deprecate both or remove both.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I included Uint32, I think if the tests all pass things should be fine. |
||
| allTypes[name] = allTypes[english_lower(name)] | ||
| sctypeDict[name] = sctypeDict[english_lower(name)] | ||
|
|
||
| _add_aliases() | ||
|
|
||
| def _add_integer_aliases(): | ||
|
|
@@ -157,20 +133,15 @@ def _add_integer_aliases(): | |
| u_info = _concrete_typeinfo[u_ctype] | ||
| bits = i_info.bits # same for both | ||
|
|
||
| for info, charname, intname, Intname in [ | ||
| (i_info,'i%d' % (bits//8,), 'int%d' % bits, 'Int%d' % bits), | ||
| (u_info,'u%d' % (bits//8,), 'uint%d' % bits, 'UInt%d' % bits)]: | ||
| for info, charname, intname in [ | ||
| (i_info,'i%d' % (bits//8,), 'int%d' % bits), | ||
| (u_info,'u%d' % (bits//8,), 'uint%d' % bits)]: | ||
| if bits not in seen_bits: | ||
| # sometimes two different types have the same number of bits | ||
| # if so, the one iterated over first takes precedence | ||
| allTypes[intname] = info.type | ||
| sctypeDict[intname] = info.type | ||
| sctypeDict[Intname] = info.type | ||
| sctypeDict[charname] = info.type | ||
| sctypeNA[Intname] = info.type | ||
| sctypeNA[charname] = info.type | ||
| sctypeNA[info.type] = Intname | ||
| sctypeNA[info.char] = Intname | ||
|
|
||
| seen_bits.add(bits) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -313,19 +313,14 @@ def test_insufficient_width_negative(self): | |||||
|
|
||||||
| class TestNumericStyleTypecodes(_DeprecationTestCase): | ||||||
| """ | ||||||
| Deprecate the old numeric-style dtypes, which are especially | ||||||
| confusing for complex types, e.g. Complex32 -> complex64. When the | ||||||
| deprecation cycle is complete, the check for the strings should be | ||||||
| removed from PyArray_DescrConverter in descriptor.c, and the | ||||||
| deprecated keys should not be added as capitalized aliases in | ||||||
| _add_aliases in numerictypes.py. | ||||||
| Most numeric style typecodes were previously deprecated (and removed) | ||||||
| in 1.20. This also deprecates the remaining ones. | ||||||
| """ | ||||||
| # 2020-06-09, NumPy 1.20 | ||||||
| def test_all_dtypes(self): | ||||||
| deprecated_types = [ | ||||||
| 'Bool', 'Complex32', 'Complex64', 'Float16', 'Float32', 'Float64', | ||||||
| 'Int8', 'Int16', 'Int32', 'Int64', 'Object0', 'Timedelta64', | ||||||
| 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Void0' | ||||||
| ] | ||||||
| deprecated_types = ['Bytes0', 'Datetime64', 'Str0'] | ||||||
| # Depending on intp size, either Uint32 or Uint64 is defined: | ||||||
| deprecated_types.append(f"U{np.dtype(np.intp).name}") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks nicer, I am a bit uncertain about locales here since the other code used
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, safer to leave it as is. |
||||||
| for dt in deprecated_types: | ||||||
| self.assert_deprecated(np.dtype, exceptions=(TypeError,), | ||||||
| args=(dt,)) | ||||||
|
|
@@ -438,14 +433,6 @@ def test_generator_sum(self): | |||||
| self.assert_deprecated(np.sum, args=((i for i in range(5)),)) | ||||||
|
|
||||||
|
|
||||||
| class TestSctypeNA(_VisibleDeprecationTestCase): | ||||||
| # 2018-06-24, 1.16 | ||||||
| def test_sctypeNA(self): | ||||||
| self.assert_deprecated(lambda: np.sctypeNA['?']) | ||||||
| self.assert_deprecated(lambda: np.typeNA['?']) | ||||||
| self.assert_deprecated(lambda: np.typeNA.get('?')) | ||||||
|
|
||||||
|
|
||||||
| class TestPositiveOnNonNumerical(_DeprecationTestCase): | ||||||
| # 2018-06-28, 1.16.0 | ||||||
| def test_positive_on_non_number(self): | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
english_capitalizeused any more?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I hardcoded the few exceptions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is, can its definition be removed too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being unclear, yes it can be, there are no more usages in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eric-wieser one quick question to be sure.
Uin32was never defined on windows? Because otherwise I have to check for (and add it) here... (or remove both)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uint32was defined on 32-bit windows only.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, its a 32bit thing... In any case, will fix this up then.
Cool about gh-14882 seems there is consensus on moving forward with it, so I will definitely review and put that in soon!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping on this - we may as well remove it from
_string_helpersif it has no other callers.