Skip to content

Commit 1f1e13f

Browse files
authoredApr 3, 2025··
MNT: Bump dev pin on NumPy (#60987)
* MNT: Bump dev pin on NumPy * Fix type-hints * Docs fixup * fixups * Fixup * Fixup * doctest fixups * More doc fixes * Some reverts * Avoid float16 * Cleanup * Remove repr from MyExtensionArray * Fixup
1 parent 7e4d306 commit 1f1e13f

File tree

23 files changed

+99
-78
lines changed

23 files changed

+99
-78
lines changed
 

‎asv_bench/benchmarks/indexing_engines.py

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class NumericEngineIndexing:
6767
def setup(self, engine_and_dtype, index_type, unique, N):
6868
engine, dtype = engine_and_dtype
6969

70+
if (
71+
index_type == "non_monotonic"
72+
and dtype in [np.int16, np.int8, np.uint8]
73+
and unique
74+
):
75+
# Values overflow
76+
raise NotImplementedError
77+
7078
if index_type == "monotonic_incr":
7179
if unique:
7280
arr = np.arange(N * 3, dtype=dtype)
@@ -115,6 +123,14 @@ def setup(self, engine_and_dtype, index_type, unique, N):
115123
engine, dtype = engine_and_dtype
116124
dtype = dtype.lower()
117125

126+
if (
127+
index_type == "non_monotonic"
128+
and dtype in ["int16", "int8", "uint8"]
129+
and unique
130+
):
131+
# Values overflow
132+
raise NotImplementedError
133+
118134
if index_type == "monotonic_incr":
119135
if unique:
120136
arr = np.arange(N * 3, dtype=dtype)

‎doc/source/getting_started/comparison/comparison_with_r.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ In Python, since ``a`` is a list, you can simply use list comprehension.
383383

384384
.. ipython:: python
385385
386-
a = np.array(list(range(1, 24)) + [np.NAN]).reshape(2, 3, 4)
386+
a = np.array(list(range(1, 24)) + [np.nan]).reshape(2, 3, 4)
387387
pd.DataFrame([tuple(list(x) + [val]) for x, val in np.ndenumerate(a)])
388388
389389
meltlist
@@ -402,7 +402,7 @@ In Python, this list would be a list of tuples, so
402402

403403
.. ipython:: python
404404
405-
a = list(enumerate(list(range(1, 5)) + [np.NAN]))
405+
a = list(enumerate(list(range(1, 5)) + [np.nan]))
406406
pd.DataFrame(a)
407407
408408
For more details and examples see :ref:`the Intro to Data Structures

‎doc/source/user_guide/basics.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2064,12 +2064,12 @@ different numeric dtypes will **NOT** be combined. The following example will gi
20642064

20652065
.. ipython:: python
20662066
2067-
df1 = pd.DataFrame(np.random.randn(8, 1), columns=["A"], dtype="float32")
2067+
df1 = pd.DataFrame(np.random.randn(8, 1), columns=["A"], dtype="float64")
20682068
df1
20692069
df1.dtypes
20702070
df2 = pd.DataFrame(
20712071
{
2072-
"A": pd.Series(np.random.randn(8), dtype="float16"),
2072+
"A": pd.Series(np.random.randn(8), dtype="float32"),
20732073
"B": pd.Series(np.random.randn(8)),
20742074
"C": pd.Series(np.random.randint(0, 255, size=8), dtype="uint8"), # [0,255] (range of uint8)
20752075
}

‎doc/source/user_guide/enhancingperf.rst

+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ can be improved by passing an ``np.ndarray``.
171171
In [4]: %%cython
172172
...: cimport numpy as np
173173
...: import numpy as np
174+
...: np.import_array()
174175
...: cdef double f_typed(double x) except? -2:
175176
...: return x * (x - 1)
176177
...: cpdef double integrate_f_typed(double a, double b, int N):
@@ -225,6 +226,7 @@ and ``wraparound`` checks can yield more performance.
225226
...: cimport cython
226227
...: cimport numpy as np
227228
...: import numpy as np
229+
...: np.import_array()
228230
...: cdef np.float64_t f_typed(np.float64_t x) except? -2:
229231
...: return x * (x - 1)
230232
...: cpdef np.float64_t integrate_f_typed(np.float64_t a, np.float64_t b, np.int64_t N):

‎doc/source/whatsnew/v0.11.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ Numeric dtypes will propagate and can coexist in DataFrames. If a dtype is passe
7474

7575
.. ipython:: python
7676
77-
df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float32')
77+
df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float64')
7878
df1
7979
df1.dtypes
80-
df2 = pd.DataFrame({'A': pd.Series(np.random.randn(8), dtype='float16'),
80+
df2 = pd.DataFrame({'A': pd.Series(np.random.randn(8), dtype='float32'),
8181
'B': pd.Series(np.random.randn(8)),
8282
'C': pd.Series(range(8), dtype='uint8')})
8383
df2

‎environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323

2424
# required dependencies
2525
- python-dateutil
26-
- numpy<2
26+
- numpy<3
2727

2828
# optional dependencies
2929
- beautifulsoup4>=4.11.2

‎pandas/compat/numpy/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
r".*In the future `np\.long` will be defined as.*",
3737
FutureWarning,
3838
)
39-
np_long = np.long # type: ignore[attr-defined]
40-
np_ulong = np.ulong # type: ignore[attr-defined]
39+
np_long = np.long
40+
np_ulong = np.ulong
4141
except AttributeError:
4242
np_long = np.int_
4343
np_ulong = np.uint

‎pandas/core/accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
351351
AttributeError: The series must contain integer data only.
352352
>>> df = pd.Series([1, 2, 3])
353353
>>> df.int_accessor.sum()
354-
6"""
354+
np.int64(6)"""
355355

356356

357357
@doc(_register_accessor, klass="Series", examples=_register_series_examples)

‎pandas/core/arrays/base.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ def argmin(self, skipna: bool = True) -> int:
941941
--------
942942
>>> arr = pd.array([3, 1, 2, 5, 4])
943943
>>> arr.argmin()
944-
1
944+
np.int64(1)
945945
"""
946946
# Implementer note: You have two places to override the behavior of
947947
# argmin.
@@ -975,7 +975,7 @@ def argmax(self, skipna: bool = True) -> int:
975975
--------
976976
>>> arr = pd.array([3, 1, 2, 5, 4])
977977
>>> arr.argmax()
978-
3
978+
np.int64(3)
979979
"""
980980
# Implementer note: You have two places to override the behavior of
981981
# argmax.
@@ -1959,10 +1959,10 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]:
19591959
--------
19601960
>>> class MyExtensionArray(pd.arrays.NumpyExtensionArray):
19611961
... def _formatter(self, boxed=False):
1962-
... return lambda x: "*" + str(x) + "*" if boxed else repr(x) + "*"
1962+
... return lambda x: "*" + str(x) + "*"
19631963
>>> MyExtensionArray(np.array([1, 2, 3, 4]))
19641964
<MyExtensionArray>
1965-
[1*, 2*, 3*, 4*]
1965+
[*1*, *2*, *3*, *4*]
19661966
Length: 4, dtype: int64
19671967
"""
19681968
if boxed:
@@ -2176,15 +2176,15 @@ def _reduce(
21762176
Examples
21772177
--------
21782178
>>> pd.array([1, 2, 3])._reduce("min")
2179-
1
2179+
np.int64(1)
21802180
>>> pd.array([1, 2, 3])._reduce("max")
2181-
3
2181+
np.int64(3)
21822182
>>> pd.array([1, 2, 3])._reduce("sum")
2183-
6
2183+
np.int64(6)
21842184
>>> pd.array([1, 2, 3])._reduce("mean")
2185-
2.0
2185+
np.float64(2.0)
21862186
>>> pd.array([1, 2, 3])._reduce("median")
2187-
2.0
2187+
np.float64(2.0)
21882188
"""
21892189
meth = getattr(self, name, None)
21902190
if meth is None:

‎pandas/core/arrays/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _unbox_scalar(
275275
--------
276276
>>> arr = pd.array(np.array(["1970-01-01"], "datetime64[ns]"))
277277
>>> arr._unbox_scalar(arr[0])
278-
numpy.datetime64('1970-01-01T00:00:00.000000000')
278+
np.datetime64('1970-01-01T00:00:00.000000000')
279279
"""
280280
raise AbstractMethodError(self)
281281

‎pandas/core/arrays/interval.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,8 @@ def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
17751775
[(0, 1], (1, 2]]
17761776
Length: 2, dtype: interval[int64, right]
17771777
>>> idx.to_tuples()
1778-
array([(0, 1), (1, 2)], dtype=object)
1778+
array([(np.int64(0), np.int64(1)), (np.int64(1), np.int64(2))],
1779+
dtype=object)
17791780
17801781
For :class:`pandas.IntervalIndex`:
17811782

‎pandas/core/arrays/masked.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -1378,25 +1378,25 @@ def any(
13781378
skips NAs):
13791379
13801380
>>> pd.array([True, False, True]).any()
1381-
True
1381+
np.True_
13821382
>>> pd.array([True, False, pd.NA]).any()
1383-
True
1383+
np.True_
13841384
>>> pd.array([False, False, pd.NA]).any()
1385-
False
1385+
np.False_
13861386
>>> pd.array([], dtype="boolean").any()
1387-
False
1387+
np.False_
13881388
>>> pd.array([pd.NA], dtype="boolean").any()
1389-
False
1389+
np.False_
13901390
>>> pd.array([pd.NA], dtype="Float64").any()
1391-
False
1391+
np.False_
13921392
13931393
With ``skipna=False``, the result can be NA if this is logically
13941394
required (whether ``pd.NA`` is True or False influences the result):
13951395
13961396
>>> pd.array([True, False, pd.NA]).any(skipna=False)
1397-
True
1397+
np.True_
13981398
>>> pd.array([1, 0, pd.NA]).any(skipna=False)
1399-
True
1399+
np.True_
14001400
>>> pd.array([False, False, pd.NA]).any(skipna=False)
14011401
<NA>
14021402
>>> pd.array([0, 0, pd.NA]).any(skipna=False)
@@ -1466,17 +1466,17 @@ def all(
14661466
skips NAs):
14671467
14681468
>>> pd.array([True, True, pd.NA]).all()
1469-
True
1469+
np.True_
14701470
>>> pd.array([1, 1, pd.NA]).all()
1471-
True
1471+
np.True_
14721472
>>> pd.array([True, False, pd.NA]).all()
1473-
False
1473+
np.False_
14741474
>>> pd.array([], dtype="boolean").all()
1475-
True
1475+
np.True_
14761476
>>> pd.array([pd.NA], dtype="boolean").all()
1477-
True
1477+
np.True_
14781478
>>> pd.array([pd.NA], dtype="Float64").all()
1479-
True
1479+
np.True_
14801480
14811481
With ``skipna=False``, the result can be NA if this is logically
14821482
required (whether ``pd.NA`` is True or False influences the result):
@@ -1486,9 +1486,9 @@ def all(
14861486
>>> pd.array([1, 1, pd.NA]).all(skipna=False)
14871487
<NA>
14881488
>>> pd.array([True, False, pd.NA]).all(skipna=False)
1489-
False
1489+
np.False_
14901490
>>> pd.array([1, 0, pd.NA]).all(skipna=False)
1491-
False
1491+
np.False_
14921492
"""
14931493
nv.validate_all((), kwargs)
14941494

‎pandas/core/arrays/sparse/accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate):
297297
--------
298298
>>> df = pd.DataFrame({"a": [1, 2, 0, 0], "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
299299
>>> df.sparse.density
300-
0.5
300+
np.float64(0.5)
301301
"""
302302

303303
def _validate(self, data) -> None:
@@ -459,7 +459,7 @@ def density(self) -> float:
459459
--------
460460
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
461461
>>> df.sparse.density
462-
0.5
462+
np.float64(0.5)
463463
"""
464464
tmp = np.mean([column.array.density for _, column in self._parent.items()])
465465
return tmp

‎pandas/core/base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,9 @@ def argmax(
804804
dtype: float64
805805
806806
>>> s.argmax()
807-
2
807+
np.int64(2)
808808
>>> s.argmin()
809-
0
809+
np.int64(0)
810810
811811
The maximum cereal calories is the third element and
812812
the minimum cereal calories is the first element,
@@ -1360,7 +1360,7 @@ def factorize(
13601360
dtype: int64
13611361
13621362
>>> ser.searchsorted(4)
1363-
3
1363+
np.int64(3)
13641364
13651365
>>> ser.searchsorted([0, 4])
13661366
array([0, 3])
@@ -1379,7 +1379,7 @@ def factorize(
13791379
dtype: datetime64[s]
13801380
13811381
>>> ser.searchsorted('3/14/2000')
1382-
3
1382+
np.int64(3)
13831383
13841384
>>> ser = pd.Categorical(
13851385
... ['apple', 'bread', 'bread', 'cheese', 'milk'], ordered=True
@@ -1389,7 +1389,7 @@ def factorize(
13891389
Categories (4, object): ['apple' < 'bread' < 'cheese' < 'milk']
13901390
13911391
>>> ser.searchsorted('bread')
1392-
1
1392+
np.int64(1)
13931393
13941394
>>> ser.searchsorted(['bread'], side='right')
13951395
array([3])

‎pandas/core/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLi
246246
with warnings.catch_warnings():
247247
# Can remove warning filter once NumPy 1.24 is min version
248248
if not np_version_gte1p24:
249-
warnings.simplefilter("ignore", np.VisibleDeprecationWarning)
249+
# np.VisibleDeprecationWarning only in np.exceptions in 2.0
250+
warnings.simplefilter("ignore", np.VisibleDeprecationWarning) # type: ignore[attr-defined]
250251
result = np.asarray(values, dtype=dtype)
251252
except ValueError:
252253
# Using try/except since it's more performant than checking is_list_like

‎pandas/core/dtypes/missing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ def array_equivalent(
428428
Examples
429429
--------
430430
>>> array_equivalent(np.array([1, 2, np.nan]), np.array([1, 2, np.nan]))
431-
True
431+
np.True_
432432
>>> array_equivalent(np.array([1, np.nan, 2]), np.array([1, 2, np.nan]))
433-
False
433+
np.False_
434434
"""
435435
left, right = np.asarray(left), np.asarray(right)
436436

@@ -626,7 +626,7 @@ def na_value_for_dtype(dtype: DtypeObj, compat: bool = True):
626626
>>> na_value_for_dtype(np.dtype("bool"))
627627
False
628628
>>> na_value_for_dtype(np.dtype("datetime64[ns]"))
629-
numpy.datetime64('NaT')
629+
np.datetime64('NaT')
630630
"""
631631

632632
if isinstance(dtype, ExtensionDtype):

‎pandas/core/generic.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ def squeeze(self, axis: Axis | None = None) -> Scalar | Series | DataFrame:
886886
dtype: int64
887887
888888
>>> even_primes.squeeze()
889-
2
889+
np.int64(2)
890890
891891
Squeezing objects with more than one value in every axis does nothing:
892892
@@ -944,7 +944,7 @@ def squeeze(self, axis: Axis | None = None) -> Scalar | Series | DataFrame:
944944
Squeezing all axes will project directly into a scalar:
945945
946946
>>> df_0a.squeeze()
947-
1
947+
np.int64(1)
948948
"""
949949
axes = range(self._AXIS_LEN) if axis is None else (self._get_axis_number(axis),)
950950
result = self.iloc[
@@ -7953,7 +7953,7 @@ def asof(self, where, subset=None):
79537953
dtype: float64
79547954
79557955
>>> s.asof(20)
7956-
2.0
7956+
np.float64(2.0)
79577957
79587958
For a sequence `where`, a Series is returned. The first value is
79597959
NaN, because the first element of `where` is before the first
@@ -7968,7 +7968,7 @@ def asof(self, where, subset=None):
79687968
NaN, even though NaN is at the index location for ``30``.
79697969
79707970
>>> s.asof(30)
7971-
2.0
7971+
np.float64(2.0)
79727972
79737973
Take all columns into consideration
79747974

0 commit comments

Comments
 (0)
Please sign in to comment.