Skip to content

Commit ecc1049

Browse files
authored
MAINT: Reflect changes from numpy namespace refactor Part 5 (#54894)
MAINT: Refactor recarray access
1 parent 1e482de commit ecc1049

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
@@ -2412,7 +2412,7 @@ def maybe_reorder(
24122412

24132413
def to_records(
24142414
self, index: bool = True, column_dtypes=None, index_dtypes=None
2415-
) -> np.recarray:
2415+
) -> np.rec.recarray:
24162416
"""
24172417
Convert DataFrame to a NumPy record array.
24182418
@@ -2437,15 +2437,15 @@ def to_records(
24372437
24382438
Returns
24392439
-------
2440-
numpy.recarray
2440+
numpy.rec.recarray
24412441
NumPy ndarray with the DataFrame labels as fields and each row
24422442
of the DataFrame as entries.
24432443
24442444
See Also
24452445
--------
24462446
DataFrame.from_records: Convert structured or record ndarray
24472447
to DataFrame.
2448-
numpy.recarray: An ndarray that allows field access using
2448+
numpy.rec.recarray: An ndarray that allows field access using
24492449
attributes, analogous to typed columns in a
24502450
spreadsheet.
24512451

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
@@ -2963,7 +2963,7 @@ def _convert_strls(self, data: DataFrame) -> DataFrame:
29632963
"""No-op, future compatibility"""
29642964
return data
29652965

2966-
def _prepare_data(self) -> np.recarray:
2966+
def _prepare_data(self) -> np.rec.recarray:
29672967
data = self.data
29682968
typlist = self.typlist
29692969
convert_dates = self._convert_dates
@@ -2995,7 +2995,7 @@ def _prepare_data(self) -> np.recarray:
29952995

29962996
return data.to_records(index=False, column_dtypes=dtypes)
29972997

2998-
def _write_data(self, records: np.recarray) -> None:
2998+
def _write_data(self, records: np.rec.recarray) -> None:
29992999
self._write_bytes(records.tobytes())
30003000

30013001
@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)