Skip to content

Commit 8ac4f39

Browse files
committed
Merge remote-tracking branch 'upstream/master' into string-use-inf-as-na
2 parents e80d100 + 12c9c62 commit 8ac4f39

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

asv_bench/benchmarks/rolling.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,18 @@ def time_quantile(self, constructor, window, dtype, percentile, interpolation):
150150
self.roll.quantile(percentile, interpolation=interpolation)
151151

152152

153-
class PeakMemFixed:
154-
def setup(self):
155-
N = 10
156-
arr = 100 * np.random.random(N)
157-
self.roll = pd.Series(arr).rolling(10)
158-
159-
def peakmem_fixed(self):
160-
# GH 25926
161-
# This is to detect memory leaks in rolling operations.
162-
# To save time this is only ran on one method.
163-
# 6000 iterations is enough for most types of leaks to be detected
164-
for x in range(6000):
165-
self.roll.max()
153+
class PeakMemFixedWindowMinMax:
154+
155+
params = ["min", "max"]
156+
157+
def setup(self, operation):
158+
N = int(1e6)
159+
arr = np.random.random(N)
160+
self.roll = pd.Series(arr).rolling(2)
161+
162+
def peakmem_fixed(self, operation):
163+
for x in range(5):
164+
getattr(self.roll, operation)()
166165

167166

168167
class ForwardWindowMethods:

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ Groupby/resample/rolling
698698
- Bug in :meth:`DataFrame.resample` where an ``AmbiguousTimeError`` would be raised when the resulting timezone aware :class:`DatetimeIndex` had a DST transition at midnight (:issue:`25758`)
699699
- Bug in :meth:`DataFrame.groupby` where a ``ValueError`` would be raised when grouping by a categorical column with read-only categories and ``sort=False`` (:issue:`33410`)
700700
- Bug in :meth:`GroupBy.first` and :meth:`GroupBy.last` where None is not preserved in object dtype (:issue:`32800`)
701+
- Bug in :meth:`Rolling.min` and :meth:`Rolling.max`: Growing memory usage after multiple calls when using a fixed window (:issue:`30726`)
701702

702703
Reshaping
703704
^^^^^^^^^

pandas/_libs/hashtable_class_helper.pxi.in

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
1212
from pandas._libs.tslibs.util cimport get_c_string
1313
from pandas._libs.missing cimport C_NA
1414

15-
cdef extern from "Python.h":
16-
void PyErr_Clear()
17-
1815
{{py:
1916

2017
# name, dtype, c_type
@@ -792,9 +789,9 @@ cdef class StringHashTable(HashTable):
792789
labels[i] = na_sentinel
793790
else:
794791
# if ignore_na is False, we also stringify NaN/None/etc.
795-
v = get_c_string(<str>val)
796-
if v == NULL:
797-
PyErr_Clear()
792+
try:
793+
v = get_c_string(<str>val)
794+
except UnicodeEncodeError:
798795
v = get_c_string(<str>repr(val))
799796
vecs[i] = v
800797

pandas/_libs/tslibs/util.pxd

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ cdef inline bint is_nan(object val):
219219

220220

221221
cdef inline const char* get_c_string_buf_and_size(str py_string,
222-
Py_ssize_t *length):
222+
Py_ssize_t *length) except NULL:
223223
"""
224224
Extract internal char* buffer of unicode or bytes object `py_string` with
225225
getting length of this internal buffer saved in `length`.
@@ -238,12 +238,8 @@ cdef inline const char* get_c_string_buf_and_size(str py_string,
238238
-------
239239
buf : const char*
240240
"""
241-
cdef:
242-
const char *buf
241+
return PyUnicode_AsUTF8AndSize(py_string, length)
243242

244-
buf = PyUnicode_AsUTF8AndSize(py_string, length)
245-
return buf
246243

247-
248-
cdef inline const char* get_c_string(str py_string):
244+
cdef inline const char* get_c_string(str py_string) except NULL:
249245
return get_c_string_buf_and_size(py_string, NULL)

pandas/_libs/window/aggregations.pyx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ cdef inline numeric calc_mm(int64_t minp, Py_ssize_t nobs,
971971
return result
972972

973973

974-
def roll_max_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
975-
ndarray[int64_t] end, int64_t minp, int64_t win):
974+
def roll_max_fixed(float64_t[:] values, int64_t[:] start,
975+
int64_t[:] end, int64_t minp, int64_t win):
976976
"""
977977
Moving max of 1d array of any numeric type along axis=0 ignoring NaNs.
978978
@@ -988,7 +988,7 @@ def roll_max_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
988988
make the interval closed on the right, left,
989989
both or neither endpoints
990990
"""
991-
return _roll_min_max_fixed(values, start, end, minp, win, is_max=1)
991+
return _roll_min_max_fixed(values, minp, win, is_max=1)
992992

993993

994994
def roll_max_variable(ndarray[float64_t] values, ndarray[int64_t] start,
@@ -1011,8 +1011,8 @@ def roll_max_variable(ndarray[float64_t] values, ndarray[int64_t] start,
10111011
return _roll_min_max_variable(values, start, end, minp, is_max=1)
10121012

10131013

1014-
def roll_min_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
1015-
ndarray[int64_t] end, int64_t minp, int64_t win):
1014+
def roll_min_fixed(float64_t[:] values, int64_t[:] start,
1015+
int64_t[:] end, int64_t minp, int64_t win):
10161016
"""
10171017
Moving min of 1d array of any numeric type along axis=0 ignoring NaNs.
10181018
@@ -1025,7 +1025,7 @@ def roll_min_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
10251025
index : ndarray, optional
10261026
index for window computation
10271027
"""
1028-
return _roll_min_max_fixed(values, start, end, minp, win, is_max=0)
1028+
return _roll_min_max_fixed(values, minp, win, is_max=0)
10291029

10301030

10311031
def roll_min_variable(ndarray[float64_t] values, ndarray[int64_t] start,
@@ -1112,9 +1112,7 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
11121112
return output
11131113

11141114

1115-
cdef _roll_min_max_fixed(ndarray[numeric] values,
1116-
ndarray[int64_t] starti,
1117-
ndarray[int64_t] endi,
1115+
cdef _roll_min_max_fixed(numeric[:] values,
11181116
int64_t minp,
11191117
int64_t win,
11201118
bint is_max):

pandas/tests/io/parser/test_common.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,15 @@ def test_no_permission(all_parsers):
974974
msg = r"\[Errno 13\]"
975975
with tm.ensure_clean() as path:
976976
os.chmod(path, 0) # make file unreadable
977+
978+
# verify that this process cannot open the file (not running as sudo)
979+
try:
980+
with open(path):
981+
pass
982+
pytest.skip("Running as sudo.")
983+
except PermissionError:
984+
pass
985+
977986
with pytest.raises(PermissionError, match=msg) as e:
978987
parser.read_csv(path)
979988
assert path == e.value.filename

0 commit comments

Comments
 (0)