Skip to content

DEP: Remove deprecated numeric style dtype strings #19539

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

Merged
merged 11 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/release/upcoming_changes/19539.expired.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Using the strings ``"Bytes0"``, ``"Datetime64"``, ``"Str0"``, ``"Uint32"``,
and ``"Uint64"`` as a dtype will now raise a ``TypeError``.
9 changes: 0 additions & 9 deletions numpy/core/_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ def _add_aliases():
# add forward, reverse, and string mapping to numarray
sctypeDict[char] = info.type

# 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
allTypes[name] = allTypes[english_lower(name)]
sctypeDict[name] = sctypeDict[english_lower(name)]

_add_aliases()

Expand Down
16 changes: 0 additions & 16 deletions numpy/core/src/multiarray/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1722,22 +1722,6 @@ _convert_from_str(PyObject *obj, int align)
goto fail;
}

/* Check for a deprecated Numeric-style typecode */
/* `Uint` has deliberately weird uppercasing */
char *dep_tps[] = {"Bytes", "Datetime64", "Str", "Uint"};
int ndep_tps = sizeof(dep_tps) / sizeof(dep_tps[0]);
for (int i = 0; i < ndep_tps; ++i) {
char *dep_tp = dep_tps[i];

if (strncmp(type, dep_tp, strlen(dep_tp)) == 0) {
/* Deprecated 2020-06-09, NumPy 1.20 */
if (DEPRECATE("Numeric-style type codes are "
"deprecated and will result in "
"an error in the future.") < 0) {
goto fail;
}
}
}
/*
* Probably only ever dispatches to `_convert_from_type`, but who
* knows what users are injecting into `np.typeDict`.
Expand Down
15 changes: 0 additions & 15 deletions numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,6 @@ def test_insufficient_width_negative(self):
self.assert_deprecated(np.binary_repr, args=args, kwargs=kwargs)


class TestNumericStyleTypecodes(_DeprecationTestCase):
"""
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 = ['Bytes0', 'Datetime64', 'Str0']
# Depending on intp size, either Uint32 or Uint64 is defined:
deprecated_types.append(f"U{np.dtype(np.intp).name}")
for dt in deprecated_types:
self.assert_deprecated(np.dtype, exceptions=(TypeError,),
args=(dt,))


class TestDTypeAttributeIsDTypeDeprecation(_DeprecationTestCase):
# Deprecated 2021-01-05, NumPy 1.21
message = r".*`.dtype` attribute"
Expand Down
9 changes: 6 additions & 3 deletions numpy/core/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ def test_richcompare_invalid_dtype_comparison(self, operation):
operation(np.dtype(np.int32), 7)

@pytest.mark.parametrize("dtype",
['Bool', 'Complex32', 'Complex64', 'Float16', 'Float32', 'Float64',
'Int8', 'Int16', 'Int32', 'Int64', 'Object0', 'Timedelta64',
'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Void0',
['Bool', 'Bytes0', 'Complex32', 'Complex64',
'Datetime64', 'Float16', 'Float32', 'Float64',
'Int8', 'Int16', 'Int32', 'Int64',
'Object0', 'Str0', 'Timedelta64',
'UInt8', 'UInt16', 'Uint32', 'UInt32',
'Uint64', 'UInt64', 'Void0',
"Float128", "Complex128"])
def test_numeric_style_types_are_invalid(self, dtype):
with assert_raises(TypeError):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy