Skip to content

Commit 1cb8e25

Browse files
DimitriPapadopoulosjorenham
authored andcommitted
MNT Address reviewer's comments
Co-authored-by: Joren Hammudoglu <[email protected]>
1 parent 6fd4a54 commit 1cb8e25

23 files changed

+58
-46
lines changed

benchmarks/benchmarks/bench_array_coercion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ def time_asarray(self, array_like):
3636
np.asarray(array_like)
3737

3838
def time_asarray_dtype(self, array_like):
39+
np.asarray(array_like, dtype=self.int64)
40+
41+
def time_asarray_dtype_order(self, array_like):
3942
np.asarray(array_like, dtype=self.int64, order="F")
4043

4144
def time_asanyarray(self, array_like):
4245
np.asanyarray(array_like)
4346

4447
def time_asanyarray_dtype(self, array_like):
48+
np.asanyarray(array_like, dtype=self.int64)
49+
50+
def time_asanyarray_dtype_order(self, array_like):
4551
np.asanyarray(array_like, dtype=self.int64, order="F")
4652

4753
def time_ascontiguousarray(self, array_like):

numpy/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ruff: noqa: I001, F401
1+
# ruff: noqa: I001
22
import builtins
33
import sys
44
import mmap

numpy/_core/arrayprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
datetime_as_string, datetime_data, ndarray)
3838
from .fromnumeric import any
3939
from .numeric import concatenate, asarray, errstate
40-
from .numerictypes import (int_, float64, complex128, flexible)
40+
from .numerictypes import int_, float64, complex128, flexible
4141
from .overrides import array_function_dispatch, set_module
4242
from .printoptions import format_options
4343
import operator

numpy/_core/multiarray.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# These imports are needed for backward compatibility,
1414
# do not change them. issue gh-15518
1515
# _get_ndarray_c_version is semi-public, on purpose not added to __all__
16-
from ._multiarray_umath import (
17-
_flagdict, from_dlpack, _place, _reconstruct, # noqa: F401
18-
_vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version, # noqa: F401
19-
_get_madvise_hugepage, _set_madvise_hugepage, # noqa: F401
16+
from ._multiarray_umath import ( # noqa: F401
17+
_flagdict, from_dlpack, _place, _reconstruct,
18+
_vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version,
19+
_get_madvise_hugepage, _set_madvise_hugepage,
2020
)
2121

2222
__all__ = [

numpy/_core/numeric.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# ruff: noqa: F401
21
import functools
32
import itertools
43
import operator
@@ -11,7 +10,7 @@
1110
import numpy as np
1211
from . import multiarray
1312
from . import numerictypes as nt
14-
from .multiarray import (
13+
from .multiarray import ( # noqa: F401
1514
ALLOW_THREADS, BUFSIZE, CLIP, MAXDIMS, MAY_SHARE_BOUNDS, MAY_SHARE_EXACT,
1615
RAISE, WRAP, arange, array, asarray, asanyarray, ascontiguousarray,
1716
asfortranarray, broadcast, can_cast, concatenate, copyto, dot, dtype,

numpy/_core/tests/test_ufunc.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,20 @@ def test_signature_dtype_type(self):
484484
np.add(3, 4, signature=(float_dtype, float_dtype, None))
485485

486486
@pytest.mark.parametrize("get_kwarg", [
487-
param(lambda x: {"dtype": x}, id="dtype"),
488-
param(lambda x: {"signature": (x, None, None)}, id="signature")])
487+
param(lambda dt: {"dtype": dt}, id="dtype"),
488+
param(lambda dt: {"signature": (dt, None, None)}, id="signature")])
489489
def test_signature_dtype_instances_allowed(self, get_kwarg):
490+
# We allow certain dtype instances when there is a clear singleton
491+
# and the given one is equivalent; mainly for backcompat.
492+
int64 = np.dtype("int64")
493+
int64_2 = pickle.loads(pickle.dumps(int64))
494+
# Relies on pickling behavior, if assert fails just remove test...
495+
assert int64 is not int64_2
496+
497+
assert np.add(1, 2, **get_kwarg(int64_2)).dtype == int64
498+
td = np.timedelta(2, "s")
499+
assert np.add(td, td, **get_kwarg("m8")).dtype == "m8[s]"
500+
490501
msg = "The `dtype` and `signature` arguments to ufuncs"
491502

492503
with pytest.raises(TypeError, match=msg):

numpy/_core/umath.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
77
"""
88

9-
# ruff: noqa: F401
109
import numpy
1110
from . import _multiarray_umath
12-
from ._multiarray_umath import * # noqa: F403
11+
from ._multiarray_umath import *
1312
# These imports are needed for backward compatibility,
1413
# do not change them. issue gh-11862
1514
# _ones_like is semi-public, on purpose not added to __all__

numpy/_pyinstaller/hook-numpy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
https://pyinstaller.readthedocs.io/en/stable/hooks.html
66
77
"""
8-
# ruff: noqa: F401
9-
from PyInstaller.compat import is_conda, is_pure_conda
10-
from PyInstaller.utils.hooks import collect_dynamic_libs, is_module_satisfies
8+
from PyInstaller.compat import is_pure_conda
9+
from PyInstaller.utils.hooks import collect_dynamic_libs
1110

1211
# Collect all DLLs inside numpy's installation folder, dump them into built
1312
# app's root.

numpy/core/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
purposes. The original `core` was renamed to `_core` and made private.
44
`numpy.core` will be removed in the future.
55
"""
6-
# ruff: noqa: F822
76
from numpy import _core
87
from ._utils import _raise_warning
98

@@ -22,7 +21,7 @@ def _ufunc_reconstruct(module, name):
2221

2322
# force lazy-loading of submodules to ensure a warning is printed
2423

25-
__all__ = ["arrayprint", "defchararray", "_dtype_ctypes", "_dtype",
24+
__all__ = ["arrayprint", "defchararray", "_dtype_ctypes", "_dtype", # noqa: F822
2625
"einsumfunc", "fromnumeric", "function_base", "getlimits",
2726
"_internal", "multiarray", "_multiarray_umath", "numeric",
2827
"numerictypes", "overrides", "records", "shape_base", "umath"]

numpy/ctypeslib/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# ruff: noqa: F401
21
import ctypes
32
from ctypes import c_int64 as _c_intp
43

0 commit comments

Comments
 (0)