Skip to content

Commit 64d7074

Browse files
committed
Avoid .base
1 parent d765e24 commit 64d7074

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

pandas/_libs/hashtable_func_helper.pxi.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ def mode_{{dtype}}({{ctype}}[:] values, bint dropna):
347347

348348
kh_destroy_{{table_type}}(table)
349349

350-
# Note: For reasons unknown, slicing modes.base works but modes[:j+1].base
351-
# returns an object with an incorrect length
352-
return modes.base[:j + 1] # `.base` to access underlying np.ndarray
350+
# Note: For reasons unknown, slicing np.asarray(modes) works but
351+
# np.asarray(modes[:j+1]) returns an object with an incorrect length
352+
return np.asarray(modes)[:j + 1]
353353

354354
{{endfor}}

pandas/_libs/lib.pyx

+14-15
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def dicts_to_array(dicts: list, columns: list):
284284
else:
285285
result[i, j] = onan
286286

287-
return result.base # `.base` to access underlying np.ndarray
287+
return np.asarray(result)
288288

289289

290290
def fast_zip(list ndarrays):
@@ -353,7 +353,7 @@ def get_reverse_indexer(int64_t[:] indexer, Py_ssize_t length):
353353
if idx != -1:
354354
rev_indexer[idx] = i
355355

356-
return rev_indexer.base # `.base` to access underlying np.ndarray
356+
return np.asarray(rev_indexer)
357357

358358

359359
@cython.wraparound(False)
@@ -534,7 +534,7 @@ def astype_unicode(arr: ndarray, skipna: bool=False) -> ndarray[object]:
534534

535535
result[i] = arr_i
536536

537-
return result.base # `.base` to access underlying np.ndarray
537+
return np.asarray(result)
538538

539539

540540
@cython.wraparound(False)
@@ -569,7 +569,7 @@ def astype_str(arr: ndarray, skipna: bool = False) -> ndarray[object]:
569569

570570
result[i] = arr_i
571571

572-
return result.base # `.base` to access underlying np.ndarray
572+
return np.asarray(result)
573573

574574

575575
@cython.wraparound(False)
@@ -695,7 +695,7 @@ def row_bool_subset(float64_t[:, :] values,
695695
out[pos, j] = values[i, j]
696696
pos += 1
697697

698-
return out.base # `.base` to access underlying np.ndarray
698+
return np.asarray(out)
699699

700700

701701
@cython.boundscheck(False)
@@ -717,7 +717,7 @@ def row_bool_subset_object(object[:, :] values,
717717
out[pos, j] = values[i, j]
718718
pos += 1
719719

720-
return out.base # `.base` to access underlying np.ndarray
720+
return np.asarray(out)
721721

722722

723723
@cython.boundscheck(False)
@@ -1941,8 +1941,7 @@ def maybe_convert_objects(object[:] objects, bint try_float=0,
19411941

19421942
if objects is None:
19431943
# Without explicitly raising, groupby.ops _aggregate_series_pure_python
1944-
# can pass None and incorrectly raise an AttributeError when trying
1945-
# to access `objects.base` below.
1944+
# can pass None and end up returning np.array(None) below
19461945
raise TypeError
19471946

19481947
n = len(objects)
@@ -2053,7 +2052,7 @@ def maybe_convert_objects(object[:] objects, bint try_float=0,
20532052
if seen.datetimetz_:
20542053
if len({getattr(val, 'tzinfo', None) for val in objects}) == 1:
20552054
from pandas import DatetimeIndex
2056-
return DatetimeIndex(objects.base)
2055+
return DatetimeIndex(np.asarray(objects))
20572056
seen.object_ = 1
20582057

20592058
if not seen.object_:
@@ -2118,7 +2117,7 @@ def maybe_convert_objects(object[:] objects, bint try_float=0,
21182117
elif seen.is_bool:
21192118
return bools.view(np.bool_)
21202119

2121-
return objects.base # `.base` to access underlying np.ndarray
2120+
return np.asarray(objects)
21222121

21232122

21242123
def map_infer_mask(ndarray arr, object f, uint8_t[:] mask, bint convert=1):
@@ -2161,7 +2160,7 @@ def map_infer_mask(ndarray arr, object f, uint8_t[:] mask, bint convert=1):
21612160
convert_datetime=0,
21622161
convert_timedelta=0)
21632162

2164-
return result.base # `.base` to access underlying np.ndarray
2163+
return np.asarray(result)
21652164

21662165

21672166
@cython.wraparound(False)
@@ -2203,7 +2202,7 @@ def map_infer(ndarray arr, object f, bint convert=1):
22032202
convert_datetime=0,
22042203
convert_timedelta=0)
22052204

2206-
return result.base # `.base` to access underlying np.ndarray
2205+
return np.asarray(result)
22072206

22082207

22092208
def to_object_array(rows: list, min_width: int = 0):
@@ -2245,7 +2244,7 @@ def to_object_array(rows: list, min_width: int = 0):
22452244
for j in range(len(row)):
22462245
result[i, j] = row[j]
22472246

2248-
return result.base # `.base` to access underlying np.ndarray
2247+
return np.asarray(result)
22492248

22502249

22512250
def tuples_to_object_array(ndarray[object] tuples):
@@ -2262,7 +2261,7 @@ def tuples_to_object_array(ndarray[object] tuples):
22622261
for j in range(k):
22632262
result[i, j] = tup[j]
22642263

2265-
return result.base # `.base` to access underlying np.ndarray
2264+
return np.asarray(result)
22662265

22672266

22682267
def to_object_array_tuples(rows: list):
@@ -2293,7 +2292,7 @@ def to_object_array_tuples(rows: list):
22932292
for j in range(len(row)):
22942293
result[i, j] = row[j]
22952294

2296-
return result.base # `.base` to access underlying np.ndarray
2295+
return np.asarray(result)
22972296

22982297

22992298
@cython.wraparound(False)

0 commit comments

Comments
 (0)