Skip to content

Commit c1353e9

Browse files
Backport PR #54894 on branch 2.1.x (MAINT: Reflect changes from numpy namespace refactor Part 5) (#54905)
Backport PR #54894: MAINT: Reflect changes from `numpy` namespace refactor Part 5 Co-authored-by: Mateusz Sokół <[email protected]>
1 parent c85679c commit c1353e9

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

pandas/core/dtypes/missing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def _isna_array(values: ArrayLike, inf_as_na: bool = False):
285285
# "Union[ndarray[Any, Any], ExtensionArraySupportsAnyAll]", variable has
286286
# type "ndarray[Any, dtype[bool_]]")
287287
result = values.isna() # type: ignore[assignment]
288-
elif isinstance(values, np.recarray):
288+
elif isinstance(values, np.rec.recarray):
289289
# GH 48526
290290
result = _isna_recarray_dtype(values, inf_as_na=inf_as_na)
291291
elif is_string_or_object_np_dtype(values.dtype):
@@ -332,7 +332,9 @@ def _has_record_inf_value(record_as_array: np.ndarray) -> np.bool_:
332332
return np.any(is_inf_in_record)
333333

334334

335-
def _isna_recarray_dtype(values: np.recarray, inf_as_na: bool) -> npt.NDArray[np.bool_]:
335+
def _isna_recarray_dtype(
336+
values: np.rec.recarray, inf_as_na: bool
337+
) -> npt.NDArray[np.bool_]:
336338
result = np.zeros(values.shape, dtype=bool)
337339
for i, record in enumerate(values):
338340
record_as_array = np.array(record.tolist())

pandas/core/frame.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ def maybe_reorder(
24022402

24032403
def to_records(
24042404
self, index: bool = True, column_dtypes=None, index_dtypes=None
2405-
) -> np.recarray:
2405+
) -> np.rec.recarray:
24062406
"""
24072407
Convert DataFrame to a NumPy record array.
24082408
@@ -2427,15 +2427,15 @@ def to_records(
24272427
24282428
Returns
24292429
-------
2430-
numpy.recarray
2430+
numpy.rec.recarray
24312431
NumPy ndarray with the DataFrame labels as fields and each row
24322432
of the DataFrame as entries.
24332433
24342434
See Also
24352435
--------
24362436
DataFrame.from_records: Convert structured or record ndarray
24372437
to DataFrame.
2438-
numpy.recarray: An ndarray that allows field access using
2438+
numpy.rec.recarray: An ndarray that allows field access using
24392439
attributes, analogous to typed columns in a
24402440
spreadsheet.
24412441

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def arrays_to_mgr(
159159

160160

161161
def rec_array_to_mgr(
162-
data: np.recarray | np.ndarray,
162+
data: np.rec.recarray | np.ndarray,
163163
index,
164164
columns,
165165
dtype: DtypeObj | None,

pandas/io/stata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,7 @@ def _convert_strls(self, data: DataFrame) -> DataFrame:
29612961
"""No-op, future compatibility"""
29622962
return data
29632963

2964-
def _prepare_data(self) -> np.recarray:
2964+
def _prepare_data(self) -> np.rec.recarray:
29652965
data = self.data
29662966
typlist = self.typlist
29672967
convert_dates = self._convert_dates
@@ -2993,7 +2993,7 @@ def _prepare_data(self) -> np.recarray:
29932993

29942994
return data.to_records(index=False, column_dtypes=dtypes)
29952995

2996-
def _write_data(self, records: np.recarray) -> None:
2996+
def _write_data(self, records: np.rec.recarray) -> None:
29972997
self._write_bytes(records.tobytes())
29982998

29992999
@staticmethod

pandas/tests/frame/constructors/test_from_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_from_records_sequencelike(self):
9393
tup.extend(b.iloc[i].values)
9494
tuples.append(tuple(tup))
9595

96-
recarray = np.array(tuples, dtype=dtypes).view(np.recarray)
96+
recarray = np.array(tuples, dtype=dtypes).view(np.rec.recarray)
9797
recarray2 = df.to_records()
9898
lists = [list(x) for x in tuples]
9999

pandas/tests/frame/methods/test_to_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def test_to_records_dtype(self, kwargs, expected):
391391
# see GH#18146
392392
df = DataFrame({"A": [1, 2], "B": [0.2, 1.5], "C": ["a", "bc"]})
393393

394-
if not isinstance(expected, np.recarray):
394+
if not isinstance(expected, np.rec.recarray):
395395
with pytest.raises(expected[0], match=expected[1]):
396396
df.to_records(**kwargs)
397397
else:

0 commit comments

Comments
 (0)