Skip to content

Commit 0fb5cfe

Browse files
authored
PERF: Only copy in plotting when needed (#58958)
* PERF: Only copy in plotting when needed * Remove more unnecessary copies
1 parent 6895f74 commit 0fb5cfe

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

pandas/plotting/_core.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,7 @@ def __call__(self, *args, **kwargs):
982982
f"Valid plot kinds: {self._all_kinds}"
983983
)
984984

985-
# The original data structured can be transformed before passed to the
986-
# backend. For example, for DataFrame is common to set the index as the
987-
# `x` parameter, and return a Series with the parameter `y` as values.
988-
data = self._parent.copy()
985+
data = self._parent
989986

990987
if isinstance(data, ABCSeries):
991988
kwargs["reuse_plot"] = True
@@ -1005,7 +1002,7 @@ def __call__(self, *args, **kwargs):
10051002
if is_integer(y) and not holds_integer(data.columns):
10061003
y = data.columns[y]
10071004
# converted to series actually. copy to not modify
1008-
data = data[y].copy()
1005+
data = data[y].copy(deep=False)
10091006
data.index.name = y
10101007
elif isinstance(data, ABCDataFrame):
10111008
data_cols = data.columns
@@ -1032,8 +1029,7 @@ def __call__(self, *args, **kwargs):
10321029
except (IndexError, KeyError, TypeError):
10331030
pass
10341031

1035-
# don't overwrite
1036-
data = data[y].copy()
1032+
data = data[y]
10371033

10381034
if isinstance(data, ABCSeries):
10391035
label_name = label_kw or y

pandas/tests/plotting/frame/test_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def test_boxplot_return_type_invalid_type(self, return_type):
11201120

11211121
def test_kde_df(self):
11221122
pytest.importorskip("scipy")
1123-
df = DataFrame(np.random.default_rng(2).standard_normal((100, 4)))
1123+
df = DataFrame(np.random.default_rng(2).standard_normal((10, 4)))
11241124
ax = _check_plot_works(df.plot, kind="kde")
11251125
expected = [pprint_thing(c) for c in df.columns]
11261126
_check_legend_labels(ax, labels=expected)

0 commit comments

Comments
 (0)