Running mypy on script with pd.pivot_table gets exponentially slower with more columns

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

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

評価

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

調査の方向性

まず、提供された Python 再現プログラムを mypy 1.7.0 で実行し、選択する列が増えるにつれて実行時間を比較します。型チェックの経路をプロファイリングして増加の原因を特定します。大きい方の列セットで、動作を変更せずに再現プログラムが 1 秒未満で完了すれば完了とします。

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

説明

bug performance

Bug Report

When running mypy on a script containing pd.pivot_table, the amount of time for mypy to finish grows exponentially with the number of columns selected and aggregated in the table.

To Reproduce

from string import ascii_letters

import numpy as np
import pandas as pd

df = pd.DataFrame({letter: [1, 2, 3] for letter in ascii_letters[:14]})

df2 = pd.pivot_table(
    df,
    values=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"],
    columns=["a"],
    aggfunc={
        "a": np.sum,
        "b": np.sum,
        "c": np.sum,
        "d": np.sum,
        "e": np.sum,
        "f": np.sum,
        "g": np.sum,
        "h": np.sum,
        "i": np.sum,
        "j": np.sum,
        "k": np.sum,
        "l": np.sum,
        "m": np.sum,
        "n": np.sum,
    },
)

Expected Behavior

It should finish in <1s, like it does if there are fewer columns

image

Actual Behavior

Takes 200 seconds to run mypy on this script

Your Environment

  • Mypy version used: 1.7.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.8.15
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

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

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

はじめの一歩

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

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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