Skip to content

Commit e151183

Browse files
author
MomIsBestFriend
committed
Reverted bad code
1 parent 362e1f7 commit e151183

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

pandas/_libs/lib.pyx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t:
118118

119119
Does not include the actual bytes of the pointers
120120
"""
121+
i: Py_ssize_t
122+
n: Py_ssize_t
121123
size: int64_t
122124

123125
size = 0
124-
for value in arr:
125-
size += value.__sizeof__()
126+
n = len(arr)
127+
for i in range(n):
128+
size += arr[i].__sizeof__()
126129
return size
127130

128131

@@ -279,17 +282,21 @@ def fast_unique_multiple(list arrays, sort: bool = True):
279282
list of unique values
280283
"""
281284
cdef:
282-
ndarray[object] buf_array
285+
ndarray[object] buf
286+
Py_ssize_t k = len(arrays)
287+
Py_ssize_t i, j, n
283288
list uniques = []
284289
dict table = {}
285-
object value, stub = 0
286-
290+
object val, stub = 0
287291

288-
for buf_array in arrays:
289-
for value in buf_array:
290-
if value not in table:
291-
table[value] = stub
292-
uniques.append(value)
292+
for i in range(k):
293+
buf = arrays[i]
294+
n = len(buf)
295+
for j in range(n):
296+
val = buf[j]
297+
if val not in table:
298+
table[val] = stub
299+
uniques.append(val)
293300

294301
if sort is None:
295302
try:

pandas/_libs/reshape.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ def explode(ndarray[object] values):
137137

138138
if c_is_list_like(v, False):
139139
if len(v):
140-
for value in v:
141-
result[count] = value
140+
for j in range(len(v)):
141+
result[count] = v[j]
142142
count += 1
143143
else:
144144
# empty list-like, use a nan marker

pandas/_libs/tslibs/period.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,9 +1469,12 @@ def extract_freq(ndarray[object] values):
14691469
# TODO: Change type to const object[:] when Cython supports that.
14701470

14711471
cdef:
1472+
Py_ssize_t i, n = len(values)
14721473
object value
14731474

1474-
for value in values:
1475+
for i in range(n):
1476+
value = values[i]
1477+
14751478
try:
14761479
# now Timestamp / NaT has freq attr
14771480
if is_period_object(value):
@@ -1481,7 +1484,6 @@ def extract_freq(ndarray[object] values):
14811484

14821485
raise ValueError('freq not specified and cannot be inferred')
14831486

1484-
14851487
# -----------------------------------------------------------------------
14861488
# period helpers
14871489

0 commit comments

Comments
 (0)