diff options
| author | Sebastian Berg <sebastianb@nvidia.com> | 2023-04-12 12:14:33 +0200 |
|---|---|---|
| committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-04-12 12:26:48 +0200 |
| commit | 569f7bc692aab41014ddc683c06e84e1bc276305 (patch) | |
| tree | 7e1b490fe442d71fb9bcf01eb797bfebcaac16d6 /numpy | |
| parent | 868a53b6725da70d408eb60b93a6f248cdd4b880 (diff) | |
| download | numpy-569f7bc692aab41014ddc683c06e84e1bc276305.tar.gz | |
MAINT: Move module to be `np.dtypes` and add release note
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/__init__.py | 2 | ||||
| -rw-r--r-- | numpy/core/__init__.py | 4 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 4 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/dtypemeta.c | 4 | ||||
| -rw-r--r-- | numpy/core/tests/test_dtype.py | 10 | ||||
| -rw-r--r-- | numpy/dtypes.py (renamed from numpy/types.py) | 24 | ||||
| -rw-r--r-- | numpy/dtypes.pyi (renamed from numpy/types.pyi) | 0 | ||||
| -rw-r--r-- | numpy/meson.build | 4 | ||||
| -rw-r--r-- | numpy/tests/test_public_api.py | 2 |
9 files changed, 29 insertions, 25 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index a0aa01854..ae8631387 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -140,7 +140,7 @@ else: from .core import * from . import compat from . import exceptions - from . import types + from . import dtypes from . import lib # NOTE: to be revisited following future namespace cleanup. # See gh-14454 and gh-15672 for discussion. diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py index 5193a694c..08e717363 100644 --- a/numpy/core/__init__.py +++ b/numpy/core/__init__.py @@ -143,11 +143,11 @@ def _DType_reconstruct(scalar_type): def _DType_reduce(DType): # As types/classes, most DTypes can simply be pickled by their name: - if not DType._legacy or DType.__module__ == "numpy.types": + if not DType._legacy or DType.__module__ == "numpy.dtypes": return DType.__name__ # However, user defined legacy dtypes (like rational) do not end up in - # `numpy.types` as module and do not have a public class at all. + # `numpy.dtypes` as module and do not have a public class at all. # For these, we pickle them by reconstructing them from the scalar type: scalar_type = DType.type return _DType_reconstruct, (scalar_type,) diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 537234358..b84625c77 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -4658,9 +4658,9 @@ set_typeinfo(PyObject *dict) */ if (dtypemeta_wrap_legacy_descriptor( _builtin_descrs[NPY_@NAME@], - "numpy.types." NPY_@NAME@_Name "DType", + "numpy.dtypes." NPY_@NAME@_Name "DType", #ifdef NPY_@NAME@_alias - "numpy.types." NPY_@NAME@_Alias "DType" + "numpy.dtypes." NPY_@NAME@_Alias "DType" #else NULL #endif diff --git a/numpy/core/src/multiarray/dtypemeta.c b/numpy/core/src/multiarray/dtypemeta.c index 2abbf394e..2052f17fd 100644 --- a/numpy/core/src/multiarray/dtypemeta.c +++ b/numpy/core/src/multiarray/dtypemeta.c @@ -791,7 +791,7 @@ dtypemeta_wrap_legacy_descriptor(PyArray_Descr *descr, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_base = &PyArrayDescr_Type, .tp_new = (newfunc)legacy_dtype_default_new, - .tp_doc = ( + .tp_doc = ( "DType class corresponding to the scalar type and dtype of " "the same name.\n\n" "Please see `numpy.dtype` for the typical way to create\n" @@ -895,7 +895,7 @@ dtypemeta_wrap_legacy_descriptor(PyArray_Descr *descr, /* And it to the types submodule if it is a builtin dtype */ if (!PyTypeNum_ISUSERDEF(descr->type_num)) { static PyObject *add_dtype_helper = NULL; - npy_cache_import("numpy.types", "_add_dtype_helper", &add_dtype_helper); + npy_cache_import("numpy.dtypes", "_add_dtype_helper", &add_dtype_helper); if (add_dtype_helper == NULL) { return -1; } diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 107b70835..57831f46f 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -7,7 +7,7 @@ import types from typing import Any import numpy as np -import numpy.types +import numpy.dtypes from numpy.core._rational_tests import rational from numpy.core._multiarray_tests import create_custom_field_dtype from numpy.testing import ( @@ -1572,9 +1572,9 @@ class TestDTypeClasses: dt_name += "c" sc_name = dtype.type.__name__ assert dt_name == sc_name.strip("_") - assert type(dtype).__module__ == "numpy.types" + assert type(dtype).__module__ == "numpy.dtypes" - assert getattr(numpy.types, type(dtype).__name__) is type(dtype) + assert getattr(numpy.dtypes, type(dtype).__name__) is type(dtype) else: assert type(dtype).__name__ == "dtype[rational]" assert type(dtype).__module__ == "numpy" @@ -1616,7 +1616,7 @@ class TestDTypeClasses: @pytest.mark.parametrize("int_", ["UInt", "Int"]) @pytest.mark.parametrize("size", [8, 16, 32, 64]) def test_integer_alias_names(self, int_, size): - DType = getattr(numpy.types, f"{int_}{size}DType") + DType = getattr(numpy.dtypes, f"{int_}{size}DType") sctype = getattr(numpy, f"{int_.lower()}{size}") assert DType.type is sctype assert DType.__name__.lower().removesuffix("dtype") == sctype.__name__ @@ -1625,7 +1625,7 @@ class TestDTypeClasses: ["Half", "Float", "Double", "CFloat", "CDouble"]) def test_float_alias_names(self, name): with pytest.raises(AttributeError): - getattr(numpy.types, name + "DType") is numpy.types.Float16DType + getattr(numpy.dtypes, name + "DType") is numpy.dtypes.Float16DType class TestFromCTypes: diff --git a/numpy/types.py b/numpy/dtypes.py index d58e753bc..cde18933c 100644 --- a/numpy/types.py +++ b/numpy/dtypes.py @@ -1,6 +1,10 @@ """ -Names of builtin NumPy Types (:mod:`numpy.types`) -================================================== +DType classes and utility (:mod:`numpy.dtypes`) +=============================================== + +This module is home to specific dtypes related functionality and their classes. +For more general information about dtypes, also see `numpy.dtype` and +:ref:`arrays.dtypes`. Similar to the builtin ``types`` module, this submodule defines types (classes) that are not widely used directly. @@ -15,10 +19,10 @@ DType classes ------------- The following are the classes of the corresponding NumPy dtype instances and -NumPy scalar types. The classe can be used for ``isisntance`` checks but are -otherwise not typically useful as of now. - -For general information see `numpy.dtype` and :ref:`arrays.dtypes`. +NumPy scalar types. The classe can be used for ``isinstance`` checks and can +also be instantiated or used directly. Direct use of these classes is not +typical, since their scalar counterparts (e.g. ``np.float64``) or strings +like ``"float64"` can be used. .. list-table:: :header-rows: 1 @@ -62,12 +66,12 @@ __all__ = [] def _add_dtype_helper(DType, alias): # Function to add DTypes a bit more conveniently without channeling them # through `numpy.core._multiarray_umath` namespace or similar. - from numpy import types + from numpy import dtypes - setattr(types, DType.__name__, DType) + setattr(dtypes, DType.__name__, DType) __all__.append(DType.__name__) if alias: - alias = alias.removeprefix("numpy.types.") - setattr(types, alias, DType) + alias = alias.removeprefix("numpy.dtypes.") + setattr(dtypes, alias, DType) __all__.append(alias) diff --git a/numpy/types.pyi b/numpy/dtypes.pyi index 2f7e846f2..2f7e846f2 100644 --- a/numpy/types.pyi +++ b/numpy/dtypes.pyi diff --git a/numpy/meson.build b/numpy/meson.build index 54331677c..de36e0d49 100644 --- a/numpy/meson.build +++ b/numpy/meson.build @@ -104,8 +104,8 @@ python_sources = [ 'ctypeslib.pyi', 'exceptions.py', 'exceptions.pyi', - 'types.py', - 'types.pyi', + 'dtypes.py', + 'dtypes.pyi', 'matlib.py', 'py.typed', 'version.py' diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index add444558..eaa89aa6f 100644 --- a/numpy/tests/test_public_api.py +++ b/numpy/tests/test_public_api.py @@ -136,6 +136,7 @@ PUBLIC_MODULES = ['numpy.' + s for s in [ "doc", "doc.constants", "doc.ufuncs", + "dtypes", "exceptions", "f2py", "fft", @@ -160,7 +161,6 @@ PUBLIC_MODULES = ['numpy.' + s for s in [ "random", "testing", "testing.overrides", - "types", "typing", "typing.mypy_plugin", "version", |
