Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

rerun cell with datafame make memory leak

オープン
#1,391 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
jupyter, pandas, python
領域
performance

調査の方向性

提供された Python dataframe と df_temp.head() セルの繰り返し実行を使用して、Jupyter kernel で報告されたメモリ増加を再現し、copy(deep=True) を呼び出すバージョンと比較します。表示された dataframe 出力を kernel がどのように処理するかを調査します。完了条件は、繰り返し実行しても報告された保持メモリの増加が発生しなくなり、その再現を対象とする回帰テストがあることです。

索引モデルが issue の本文から書いたものです。

説明

env

use vscode remote-ssh connect to debian server and use the jupyter

debian12
vscode=Version: 1.99.0
python=3.10
ipykernal=6.29.5
pandas=2.2.3

replay

create a big dataframe

import pandas as pd
import numpy as np

np.random.seed(0)
num_rows = 10000000  
num_cols = 10  
# create the random number
data = np.random.randint(0, 100, size=(num_rows, num_cols))
df = pd.DataFrame(data, columns=[f'col_{i}' for i in range(num_cols)])

monitor the memory use

%load_ext ipython_memory_usage
%imu_start

when rerun the cell below ,momery will used increasing

df_temp = df.copy(deep=True)
df_temp.head()

in my computer,the result like

[Out] In [4] used 763.6 MiB RAM in 0.55s (system mean cpu 40%, single max cpu 100%), peaked 0.0 MiB above final usage, current RAM usage now 1632.0 MiB

[Out] In [5] used 763.0 MiB RAM in 0.55s (system mean cpu 19%, single max cpu 100%), peaked 0.0 MiB above final usage, current RAM usage now 2394.9 MiB

[Out] In [6] used 763.1 MiB RAM in 0.55s (system mean cpu 25%, single max cpu 100%), peaked 0.0 MiB above final usage, current RAM usage now 3158.0 MiB

try to solve

After many tries , I find the main reason is df_temp.head() ;
If rerun df_temp = df.copy(deep=True) ,the used memory doesn't increase;

If change the code to

df_snapshot_test = df_snapshot.copy(deep=True)
df_snapshot_test.head().copy(deep=True)

rerun will not increase memory too;

I have try

import gc
gc.collect()  

or

from IPython.display 
import clear_output

both can't free the memory

another similar issuse

主要言語
Python
スター
734
フォーク
411
平均マージ
1日 2時間
マージ済み PR(30日)
9

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ipython/ipykernel のほかの issue

ipython/ipykernel の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。