Skip to content

Commit 5cb006f

Browse files
WillAydjreback
authored andcommitted
Fix Memory Leak in to_json with Numeric Values (#26239)
1 parent 927de02 commit 5cb006f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

asv_bench/benchmarks/io/json.py

+22
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,26 @@ def time_float_int_str_lines(self, orient):
124124
self.df_int_float_str.to_json(self.fname, orient='records', lines=True)
125125

126126

127+
class ToJSONMem:
128+
129+
def setup_cache(self):
130+
df = DataFrame([[1]])
131+
frames = {
132+
'int': df,
133+
'float': df.astype(float),
134+
}
135+
136+
return frames
137+
138+
def peakmem_int(self, frames):
139+
df = frames['int']
140+
for _ in range(100_000):
141+
df.to_json()
142+
143+
def peakmem_float(self, frames):
144+
df = frames['float']
145+
for _ in range(100_000):
146+
df.to_json()
147+
148+
127149
from ..pandas_vb_common import setup # noqa: F401

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ I/O
368368
- Improved the ``col_space`` parameter in :meth:`DataFrame.to_html` to accept a string so CSS length values can be set correctly (:issue:`25941`)
369369
- Fixed bug in loading objects from S3 that contain ``#`` characters in the URL (:issue:`25945`)
370370
- Adds ``use_bqstorage_api`` parameter to :func:`read_gbq` to speed up downloads of large data frames. This feature requires version 0.10.0 of the ``pandas-gbq`` library as well as the ``google-cloud-bigquery-storage`` and ``fastavro`` libraries. (:issue:`26104`)
371+
- Fixed memory leak in :meth:`DataFrame.to_json` when dealing with numeric data (:issue:`24889`)
371372

372373
Plotting
373374
^^^^^^^^

pandas/_libs/src/ujson/python/objToJSON.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ int NpyArr_iterNextItem(JSOBJ obj, JSONTypeContext *tc) {
709709

710710
NpyArr_freeItemValue(obj, tc);
711711

712-
if (PyArray_ISNUMBER(npyarr->array) || PyArray_ISDATETIME(npyarr->array))
712+
if (PyArray_ISDATETIME(npyarr->array))
713713
{
714714
PRINTMARK();
715715
GET_TC(tc)->itemValue = obj;

0 commit comments

Comments
 (0)