From 2f54813351a87eb50263c7965f642ec2546ea25e Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Sun, 12 Dec 2021 15:33:19 +0100 Subject: [PATCH 01/22] Rename 'c' to 'color' and 's' to 'size' This changes use more intuitive names for 'color' and 'size' and use the same notation like in '_bar_or_line_doc'. --- pandas/plotting/_core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 524a26b2d3fa6..fe094f9f8ea32 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1582,7 +1582,7 @@ def pie(self, **kwargs): raise ValueError("pie requires either y column or 'subplots=True'") return self(kind="pie", **kwargs) - def scatter(self, x, y, s=None, c=None, **kwargs): + def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs): """ Create a scatter plot with varying marker point size and color. @@ -1601,7 +1601,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): y : int or str The column name or column position to be used as vertical coordinates for each point. - s : str, scalar or array-like, optional + size : str, scalar or array-like, optional The size of each point. Possible values are: - A string with the name of the column to be used for marker's size. @@ -1614,7 +1614,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): .. versionchanged:: 1.1.0 - c : str, int or array-like, optional + color : str, int or array-like, optional The color of each point. Possible values are: - A single color string referred to by name, RGB or RGBA code, @@ -1653,7 +1653,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): ... columns=['length', 'width', 'species']) >>> ax1 = df.plot.scatter(x='length', ... y='width', - ... c='DarkBlue') + ... color='DarkBlue') And now with the color determined by a column as well. @@ -1662,10 +1662,10 @@ def scatter(self, x, y, s=None, c=None, **kwargs): >>> ax2 = df.plot.scatter(x='length', ... y='width', - ... c='species', + ... color='species', ... colormap='viridis') """ - return self(kind="scatter", x=x, y=y, s=s, c=c, **kwargs) + return self(kind="scatter", x=x, y=y, s=size or s, c=color or c, **kwargs) def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs): """ From 3feaabc0881e3a242ab014614ff9a7f0ae16711b Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Mon, 17 Jan 2022 15:03:12 +0100 Subject: [PATCH 02/22] Rework after comments --- pandas/plotting/_core.py | 41 ++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index fe094f9f8ea32..9da8de1ae3103 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1127,6 +1127,13 @@ def bar(self, x=None, y=None, **kwargs): axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ + c = kwargs.pop('c', None) + color = kwargs.pop('color', None) + if c is not None and color is not None: + raise TypeError("Specify exactly one of `c` and `color`") + if c is not None or color is not None: + kwargs.setdefault('c', color or c) + return self(kind="bar", x=x, y=y, **kwargs) @Appender( @@ -1213,6 +1220,13 @@ def barh(self, x=None, y=None, **kwargs): axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ + c = kwargs.pop('c', None) + color = kwargs.pop('color', None) + if c is not None and color is not None: + raise TypeError("Specify exactly one of `c` and `color`") + if c is not None or color is not None: + kwargs.setdefault('c', color or c) + return self(kind="barh", x=x, y=y, **kwargs) def box(self, by=None, **kwargs): @@ -1582,7 +1596,7 @@ def pie(self, **kwargs): raise ValueError("pie requires either y column or 'subplots=True'") return self(kind="pie", **kwargs) - def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs): + def scatter(self, x, y, **kwargs): """ Create a scatter plot with varying marker point size and color. @@ -1601,7 +1615,7 @@ def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs): y : int or str The column name or column position to be used as vertical coordinates for each point. - size : str, scalar or array-like, optional + s : str, scalar or array-like, optional The size of each point. Possible values are: - A string with the name of the column to be used for marker's size. @@ -1614,7 +1628,7 @@ def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs): .. versionchanged:: 1.1.0 - color : str, int or array-like, optional + c : str, int or array-like, optional The color of each point. Possible values are: - A single color string referred to by name, RGB or RGBA code, @@ -1653,7 +1667,7 @@ def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs): ... columns=['length', 'width', 'species']) >>> ax1 = df.plot.scatter(x='length', ... y='width', - ... color='DarkBlue') + ... c='DarkBlue') And now with the color determined by a column as well. @@ -1662,10 +1676,25 @@ def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs): >>> ax2 = df.plot.scatter(x='length', ... y='width', - ... color='species', + ... c='species', ... colormap='viridis') """ - return self(kind="scatter", x=x, y=y, s=size or s, c=color or c, **kwargs) + + s = kwargs.pop('s', None) + size = kwargs.pop('size', None) + if s is not None and size is not None: + raise TypeError("Specify exactly one of `s` and `size`") + if s is not None or size is not None: + kwargs.setdefault('s', s or size) + + c = kwargs.pop('c', None) + color = kwargs.pop('color', None) + if c is not None and color is not None: + raise TypeError("Specify exactly one of `c` and `color`") + if c is not None or color is not None: + kwargs.setdefault('c', c or color) + + return self(kind="scatter", x=x, y=y, **kwargs) def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs): """ From 68f25514b30615deae5e705bd3eced9d08eddf4e Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Mon, 17 Jan 2022 15:05:05 +0100 Subject: [PATCH 03/22] remove whitespace --- pandas/plotting/_core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 9da8de1ae3103..13d4834523cf4 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1679,7 +1679,6 @@ def scatter(self, x, y, **kwargs): ... c='species', ... colormap='viridis') """ - s = kwargs.pop('s', None) size = kwargs.pop('size', None) if s is not None and size is not None: From 390fc86fe28d46657cbd95fcd18ff45c6929e3d6 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Wed, 19 Jan 2022 16:49:15 +0100 Subject: [PATCH 04/22] Add Tests --- pandas/plotting/_core.py | 20 ++++++++++++++---- pandas/tests/plotting/frame/test_frame.py | 12 +++++++++++ .../tests/plotting/frame/test_frame_color.py | 21 +++++++++++++++++-- pandas/tests/plotting/test_series.py | 10 +++++++-- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 13d4834523cf4..8d46a261b3622 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1132,7 +1132,10 @@ def bar(self, x=None, y=None, **kwargs): if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") if c is not None or color is not None: - kwargs.setdefault('c', color or c) + if color is not None: + kwargs.setdefault('color', color) + else: + kwargs.setdefault('color', c) return self(kind="bar", x=x, y=y, **kwargs) @@ -1225,7 +1228,10 @@ def barh(self, x=None, y=None, **kwargs): if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") if c is not None or color is not None: - kwargs.setdefault('c', color or c) + if color is not None: + kwargs.setdefault('color', color) + else: + kwargs.setdefault('color', c) return self(kind="barh", x=x, y=y, **kwargs) @@ -1684,14 +1690,20 @@ def scatter(self, x, y, **kwargs): if s is not None and size is not None: raise TypeError("Specify exactly one of `s` and `size`") if s is not None or size is not None: - kwargs.setdefault('s', s or size) + if s is not None: + kwargs.setdefault('s', s) + else: + kwargs.setdefault('s', size) c = kwargs.pop('c', None) color = kwargs.pop('color', None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") if c is not None or color is not None: - kwargs.setdefault('c', c or color) + if c is not None: + kwargs.setdefault('c', c) + else: + kwargs.setdefault('c', color) return self(kind="scatter", x=x, y=y, **kwargs) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 6c07366e402d6..89d66ea9162b2 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -674,6 +674,14 @@ def test_plot_scatter(self): with pytest.raises(TypeError, match=msg): df.plot.scatter(y="y") + with pytest.raises(TypeError, match="Specify exactly one of `s` and `size`"): + df.plot.scatter(x="x", y="y", s=2, size=2) + with pytest.raises(TypeError, match="Specify exactly one of `c` and `color`"): + df.plot.scatter(x="a", y="b", c="red", color="green") + + default_colors = self._unpack_cycler(self.plt.rcParams) + default_colors = self._unpack_cycler(self.plt.rcParams) + # GH 6951 axes = df.plot(x="x", y="y", kind="scatter", subplots=True) self._check_axes_shape(axes, axes_num=1, layout=(1, 1)) @@ -827,6 +835,10 @@ def test_plot_bar(self): _check_plot_works(df.plot.bar) df = DataFrame({"a": [0, 1], "b": [1, 0]}) + + with pytest.raises(TypeError, match="Specify exactly one of `c` and `color`"): + df.plot.bar(x="a", y="b", c="red", color="green") + ax = _check_plot_works(df.plot.bar) self._check_ticks_props(ax, xrot=90) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index b46bb95829991..437e14eb4cc15 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -123,6 +123,11 @@ def test_bar_colors(self): self._check_colors(ax.patches[::5], facecolors=custom_colors) tm.close() + custom_colors = "rgcby" + ax = df.plot.bar(c=custom_colors) + self._check_colors(ax.patches[::5], facecolors=custom_colors) + tm.close() + from matplotlib import cm # Test str -> colormap functionality @@ -141,6 +146,10 @@ def test_bar_colors(self): self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) tm.close() + ax = df.loc[:, [0]].plot.bar(c="DodgerBlue") + self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) + tm.close() + ax = df.plot(kind="bar", color="green") self._check_colors(ax.patches[::5], facecolors=["green"] * 5) tm.close() @@ -151,15 +160,20 @@ def test_bar_user_colors(self): ) # This should *only* work when `y` is specified, else # we use one color per column - ax = df.plot.bar(y="A", color=df["color"]) - result = [p.get_facecolor() for p in ax.patches] expected = [ (1.0, 0.0, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.0, 1.0), ] + + ax = df.plot.bar(y="A", color=df["color"]) + result = [p.get_facecolor() for p in ax.patches] assert result == expected + + ax = df.plot.bar(y="A", c=df["color"]) + result = [p.get_facecolor() for p in ax.patches] + assert result == expected def test_if_scatterplot_colorbar_affects_xaxis_visibility(self): # addressing issue #10611, to ensure colobar does not @@ -223,6 +237,9 @@ def test_scatter_with_c_column_name_with_colors(self, cmap): ax = df.plot.scatter(x=0, y=1, c="species", cmap=cmap) assert ax.collections[0].colorbar is None + ax = df.plot.scatter(x=0, y=1, color="species", cmap=cmap) + assert ax.collections[0].colorbar is None + def test_scatter_colors(self): df = DataFrame({"a": [1, 2, 3], "b": [1, 2, 3], "c": [1, 2, 3]}) with pytest.raises(TypeError, match="Specify exactly one of `c` and `color`"): diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 44fc6042ebaab..692deb1197637 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -270,14 +270,20 @@ def test_bar_ignore_index(self): def test_bar_user_colors(self): s = Series([1, 2, 3, 4]) - ax = s.plot.bar(color=["red", "blue", "blue", "red"]) - result = [p.get_facecolor() for p in ax.patches] + expected = [ (1.0, 0.0, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.0, 1.0), ] + + ax = s.plot.bar(color=["red", "blue", "blue", "red"]) + result = [p.get_facecolor() for p in ax.patches] + assert result == expected + + ax = s.plot.bar(c=["red", "blue", "blue", "red"]) + result = [p.get_facecolor() for p in ax.patches] assert result == expected def test_rotation(self): From 865b7acc7dbfa5dfa7bcad02364eadd05617b35e Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Fri, 21 Jan 2022 11:26:16 +0100 Subject: [PATCH 05/22] Split test into two --- pandas/tests/plotting/test_series.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 692deb1197637..acf146cbaa451 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -282,6 +282,16 @@ def test_bar_user_colors(self): result = [p.get_facecolor() for p in ax.patches] assert result == expected + def test_bar_user_colors_c(self): + s = Series([1, 2, 3, 4]) + + expected = [ + (1.0, 0.0, 0.0, 1.0), + (0.0, 0.0, 1.0, 1.0), + (0.0, 0.0, 1.0, 1.0), + (1.0, 0.0, 0.0, 1.0), + ] + ax = s.plot.bar(c=["red", "blue", "blue", "red"]) result = [p.get_facecolor() for p in ax.patches] assert result == expected From 1f30d452dde4f009556537777f1de247e3451f31 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Fri, 21 Jan 2022 11:56:48 +0100 Subject: [PATCH 06/22] t --- pandas/tests/plotting/frame/test_frame_color.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 437e14eb4cc15..eeb22e47d1612 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -18,6 +18,8 @@ pytestmark = pytest.mark.slow + + @td.skip_if_no_mpl class TestDataFrameColor(TestPlotBase): def setup_method(self, method): From 543c64ec5639e92a294a28648c0e42701044331d Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Fri, 21 Jan 2022 11:57:02 +0100 Subject: [PATCH 07/22] Revert 't' This reverts commit 1f30d452dde4f009556537777f1de247e3451f31 --- pandas/tests/plotting/frame/test_frame_color.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index eeb22e47d1612..437e14eb4cc15 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -18,8 +18,6 @@ pytestmark = pytest.mark.slow - - @td.skip_if_no_mpl class TestDataFrameColor(TestPlotBase): def setup_method(self, method): From d1fd7bcce77d6c335dc811ee9f38760a152be6bc Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Fri, 21 Jan 2022 12:12:31 +0100 Subject: [PATCH 08/22] delete trailling whitespaces --- pandas/plotting/_core.py | 32 +++++++++---------- .../tests/plotting/frame/test_frame_color.py | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 8d46a261b3622..ea0e26ed15b3f 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1127,15 +1127,15 @@ def bar(self, x=None, y=None, **kwargs): axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - c = kwargs.pop('c', None) - color = kwargs.pop('color', None) + c = kwargs.pop("c", None) + color = kwargs.pop("color", None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") if c is not None or color is not None: if color is not None: - kwargs.setdefault('color', color) + kwargs.setdefault("color", color) else: - kwargs.setdefault('color', c) + kwargs.setdefault("color", c) return self(kind="bar", x=x, y=y, **kwargs) @@ -1223,15 +1223,15 @@ def barh(self, x=None, y=None, **kwargs): axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - c = kwargs.pop('c', None) - color = kwargs.pop('color', None) + c = kwargs.pop("c", None) + color = kwargs.pop("color", None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") if c is not None or color is not None: if color is not None: - kwargs.setdefault('color', color) + kwargs.setdefault("color", color) else: - kwargs.setdefault('color', c) + kwargs.setdefault("color", c) return self(kind="barh", x=x, y=y, **kwargs) @@ -1685,25 +1685,25 @@ def scatter(self, x, y, **kwargs): ... c='species', ... colormap='viridis') """ - s = kwargs.pop('s', None) - size = kwargs.pop('size', None) + s = kwargs.pop("s", None) + size = kwargs.pop("size", None) if s is not None and size is not None: raise TypeError("Specify exactly one of `s` and `size`") if s is not None or size is not None: if s is not None: - kwargs.setdefault('s', s) + kwargs.setdefault("s", s) else: - kwargs.setdefault('s', size) + kwargs.setdefault("s", size) - c = kwargs.pop('c', None) - color = kwargs.pop('color', None) + c = kwargs.pop("c", None) + color = kwargs.pop("color", None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") if c is not None or color is not None: if c is not None: - kwargs.setdefault('c', c) + kwargs.setdefault("c", c) else: - kwargs.setdefault('c', color) + kwargs.setdefault("c", color) return self(kind="scatter", x=x, y=y, **kwargs) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 437e14eb4cc15..3ba93051272b8 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -170,10 +170,10 @@ def test_bar_user_colors(self): ax = df.plot.bar(y="A", color=df["color"]) result = [p.get_facecolor() for p in ax.patches] assert result == expected - + ax = df.plot.bar(y="A", c=df["color"]) result = [p.get_facecolor() for p in ax.patches] - assert result == expected + assert result == expected def test_if_scatterplot_colorbar_affects_xaxis_visibility(self): # addressing issue #10611, to ensure colobar does not From eda1fbcfee64b200159c2c03650587aa8c93851d Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Fri, 21 Jan 2022 12:32:09 +0100 Subject: [PATCH 09/22] delete default_colors --- pandas/tests/plotting/frame/test_frame.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 89d66ea9162b2..470e75ac85408 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -1,4 +1,3 @@ -""" Test cases for DataFrame.plot """ from datetime import ( date, datetime, @@ -679,9 +678,6 @@ def test_plot_scatter(self): with pytest.raises(TypeError, match="Specify exactly one of `c` and `color`"): df.plot.scatter(x="a", y="b", c="red", color="green") - default_colors = self._unpack_cycler(self.plt.rcParams) - default_colors = self._unpack_cycler(self.plt.rcParams) - # GH 6951 axes = df.plot(x="x", y="y", kind="scatter", subplots=True) self._check_axes_shape(axes, axes_num=1, layout=(1, 1)) From 1caf4dc4590d355b8fff3b38aee4b38db5cab1f9 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Tue, 25 Jan 2022 11:25:34 +0100 Subject: [PATCH 10/22] accept suggestions --- pandas/plotting/_core.py | 32 ++++++++-------------------- pandas/tests/plotting/test_series.py | 19 +++-------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index ea0e26ed15b3f..626ee4c5062b9 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1131,11 +1131,8 @@ def bar(self, x=None, y=None, **kwargs): color = kwargs.pop("color", None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") - if c is not None or color is not None: - if color is not None: - kwargs.setdefault("color", color) - else: - kwargs.setdefault("color", c) + elif c is not None or color is not None: + kwargs["color"] = color if color is not None else c return self(kind="bar", x=x, y=y, **kwargs) @@ -1227,11 +1224,8 @@ def barh(self, x=None, y=None, **kwargs): color = kwargs.pop("color", None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") - if c is not None or color is not None: - if color is not None: - kwargs.setdefault("color", color) - else: - kwargs.setdefault("color", c) + elif c is not None or color is not None: + kwargs["color"] = color if color is not None else c return self(kind="barh", x=x, y=y, **kwargs) @@ -1602,7 +1596,7 @@ def pie(self, **kwargs): raise ValueError("pie requires either y column or 'subplots=True'") return self(kind="pie", **kwargs) - def scatter(self, x, y, **kwargs): + def scatter(self, x, y, s=None, c=None, **kwargs): """ Create a scatter plot with varying marker point size and color. @@ -1685,25 +1679,17 @@ def scatter(self, x, y, **kwargs): ... c='species', ... colormap='viridis') """ - s = kwargs.pop("s", None) size = kwargs.pop("size", None) if s is not None and size is not None: raise TypeError("Specify exactly one of `s` and `size`") - if s is not None or size is not None: - if s is not None: - kwargs.setdefault("s", s) - else: - kwargs.setdefault("s", size) + elif s is not None or size is not None: + kwargs["s"] = s if s is not None else size - c = kwargs.pop("c", None) color = kwargs.pop("color", None) if c is not None and color is not None: raise TypeError("Specify exactly one of `c` and `color`") - if c is not None or color is not None: - if c is not None: - kwargs.setdefault("c", c) - else: - kwargs.setdefault("c", color) + elif c is not None or color is not None: + kwargs["c"] = c if c is not None else color return self(kind="scatter", x=x, y=y, **kwargs) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index acf146cbaa451..1d2f0b201e060 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -268,7 +268,8 @@ def test_bar_ignore_index(self): ax = df.plot.bar(use_index=False, ax=ax) self._check_text_labels(ax.get_xticklabels(), ["0", "1", "2", "3"]) - def test_bar_user_colors(self): + @pytest.mark.parametrize("kw", ["c", "color"]) + def test_bar_user_colors(self, kw): s = Series([1, 2, 3, 4]) expected = [ @@ -278,21 +279,7 @@ def test_bar_user_colors(self): (1.0, 0.0, 0.0, 1.0), ] - ax = s.plot.bar(color=["red", "blue", "blue", "red"]) - result = [p.get_facecolor() for p in ax.patches] - assert result == expected - - def test_bar_user_colors_c(self): - s = Series([1, 2, 3, 4]) - - expected = [ - (1.0, 0.0, 0.0, 1.0), - (0.0, 0.0, 1.0, 1.0), - (0.0, 0.0, 1.0, 1.0), - (1.0, 0.0, 0.0, 1.0), - ] - - ax = s.plot.bar(c=["red", "blue", "blue", "red"]) + ax = s.plot.bar(**{kw: ["red", "blue", "blue", "red"]}) result = [p.get_facecolor() for p in ax.patches] assert result == expected From 021aaddc080ffb2d9784988c694cdefc1d509b9f Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Tue, 25 Jan 2022 12:05:15 +0100 Subject: [PATCH 11/22] Update pandas/tests/plotting/frame/test_frame_color.py Co-authored-by: JHM Darbyshire <24256554+attack68@users.noreply.github.com> --- pandas/tests/plotting/frame/test_frame_color.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 3ba93051272b8..16a34df5521ae 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -166,12 +166,7 @@ def test_bar_user_colors(self): (0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.0, 1.0), ] - - ax = df.plot.bar(y="A", color=df["color"]) - result = [p.get_facecolor() for p in ax.patches] - assert result == expected - - ax = df.plot.bar(y="A", c=df["color"]) + ax = df.plot.bar(y="A", **{kw: df["color"]}) result = [p.get_facecolor() for p in ax.patches] assert result == expected From 5e94951ab0a41b9fb7a94347801d840d5afcca01 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Tue, 25 Jan 2022 13:32:10 +0100 Subject: [PATCH 12/22] add docstring --- pandas/plotting/_core.py | 8 ++++++ .../tests/plotting/frame/test_frame_color.py | 26 +++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 626ee4c5062b9..dacc731d7c636 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1643,6 +1643,14 @@ def scatter(self, x, y, s=None, c=None, **kwargs): marker points according to a colormap. **kwargs + size : str, int or array-like, optional + The color of each point. Alias for `s`. + `s` and `size` aren't allowed at the same time. + .. versionadded:: 1.4.1 + color : str, int or array-like, optional + The color of each point. Alias for `c`. + `c` and `color` aren't allowed at the same time. + .. versionadded:: 1.4.1 Keyword arguments to pass on to :meth:`DataFrame.plot`. Returns diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 16a34df5521ae..39d1492e834ce 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -119,14 +119,10 @@ def test_bar_colors(self): tm.close() custom_colors = "rgcby" - ax = df.plot.bar(color=custom_colors) - self._check_colors(ax.patches[::5], facecolors=custom_colors) - tm.close() - - custom_colors = "rgcby" - ax = df.plot.bar(c=custom_colors) - self._check_colors(ax.patches[::5], facecolors=custom_colors) - tm.close() + for kw in ["c", "color"]: + ax = df.plot.bar(**{kw: "rgcby"}) + self._check_colors(ax.patches[::5], facecolors=custom_colors) + tm.close() from matplotlib import cm @@ -142,19 +138,17 @@ def test_bar_colors(self): self._check_colors(ax.patches[::5], facecolors=rgba_colors) tm.close() - ax = df.loc[:, [0]].plot.bar(color="DodgerBlue") - self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) - tm.close() - - ax = df.loc[:, [0]].plot.bar(c="DodgerBlue") - self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) - tm.close() + for kw in ["c", "color"]: + ax = df.loc[:, [0]].plot.bar(**{kw: "DodgerBlue"}) + self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) + tm.close() ax = df.plot(kind="bar", color="green") self._check_colors(ax.patches[::5], facecolors=["green"] * 5) tm.close() - def test_bar_user_colors(self): + @pytest.mark.parametrize("kw", ["c", "color"]) + def test_bar_user_colors(self, kw): df = DataFrame( {"A": range(4), "B": range(1, 5), "color": ["red", "blue", "blue", "red"]} ) From 05a26c86f685f81c0d197b7bcfb0153506a2c9e0 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Tue, 25 Jan 2022 15:23:22 +0100 Subject: [PATCH 13/22] remove c for bar and hbar --- pandas/plotting/_core.py | 14 ---------- pandas/tests/plotting/frame/test_frame.py | 3 --- .../tests/plotting/frame/test_frame_color.py | 27 ++++++++----------- pandas/tests/plotting/test_series.py | 5 ++-- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index dacc731d7c636..a4440a6e55db2 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1127,13 +1127,6 @@ def bar(self, x=None, y=None, **kwargs): axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - c = kwargs.pop("c", None) - color = kwargs.pop("color", None) - if c is not None and color is not None: - raise TypeError("Specify exactly one of `c` and `color`") - elif c is not None or color is not None: - kwargs["color"] = color if color is not None else c - return self(kind="bar", x=x, y=y, **kwargs) @Appender( @@ -1220,13 +1213,6 @@ def barh(self, x=None, y=None, **kwargs): axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - c = kwargs.pop("c", None) - color = kwargs.pop("color", None) - if c is not None and color is not None: - raise TypeError("Specify exactly one of `c` and `color`") - elif c is not None or color is not None: - kwargs["color"] = color if color is not None else c - return self(kind="barh", x=x, y=y, **kwargs) def box(self, by=None, **kwargs): diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 470e75ac85408..29a698c2c1af5 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -832,9 +832,6 @@ def test_plot_bar(self): df = DataFrame({"a": [0, 1], "b": [1, 0]}) - with pytest.raises(TypeError, match="Specify exactly one of `c` and `color`"): - df.plot.bar(x="a", y="b", c="red", color="green") - ax = _check_plot_works(df.plot.bar) self._check_ticks_props(ax, xrot=90) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 39d1492e834ce..ff3792d448520 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -119,10 +119,9 @@ def test_bar_colors(self): tm.close() custom_colors = "rgcby" - for kw in ["c", "color"]: - ax = df.plot.bar(**{kw: "rgcby"}) - self._check_colors(ax.patches[::5], facecolors=custom_colors) - tm.close() + ax = df.plot.bar(color="rgcby") + self._check_colors(ax.patches[::5], facecolors=custom_colors) + tm.close() from matplotlib import cm @@ -138,17 +137,15 @@ def test_bar_colors(self): self._check_colors(ax.patches[::5], facecolors=rgba_colors) tm.close() - for kw in ["c", "color"]: - ax = df.loc[:, [0]].plot.bar(**{kw: "DodgerBlue"}) - self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) - tm.close() + ax = df.loc[:, [0]].plot.bar(color="DodgerBlue") + self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"]) + tm.close() ax = df.plot(kind="bar", color="green") self._check_colors(ax.patches[::5], facecolors=["green"] * 5) tm.close() - @pytest.mark.parametrize("kw", ["c", "color"]) - def test_bar_user_colors(self, kw): + def test_bar_user_colors(self): df = DataFrame( {"A": range(4), "B": range(1, 5), "color": ["red", "blue", "blue", "red"]} ) @@ -160,7 +157,7 @@ def test_bar_user_colors(self, kw): (0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.0, 1.0), ] - ax = df.plot.bar(y="A", **{kw: df["color"]}) + ax = df.plot.bar(y="A", color=df["color"]) result = [p.get_facecolor() for p in ax.patches] assert result == expected @@ -216,17 +213,15 @@ def test_if_scatterplot_colorbars_are_next_to_parent_axes(self): assert np.isclose(parent_distance, colorbar_distance, atol=1e-7).all() @pytest.mark.parametrize("cmap", [None, "Greys"]) - def test_scatter_with_c_column_name_with_colors(self, cmap): + @pytest.mark.parametrize("kw", ["c", "color"]) + def test_scatter_with_c_column_name_with_colors(self, cmap, kw): # https://github.com/pandas-dev/pandas/issues/34316 df = DataFrame( [[5.1, 3.5], [4.9, 3.0], [7.0, 3.2], [6.4, 3.2], [5.9, 3.0]], columns=["length", "width"], ) df["species"] = ["r", "r", "g", "g", "b"] - ax = df.plot.scatter(x=0, y=1, c="species", cmap=cmap) - assert ax.collections[0].colorbar is None - - ax = df.plot.scatter(x=0, y=1, color="species", cmap=cmap) + ax = df.plot.scatter(x=0, y=1, cmap=cmap, **{kw: "species"}) assert ax.collections[0].colorbar is None def test_scatter_colors(self): diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 1d2f0b201e060..5745a2890cefa 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -268,8 +268,7 @@ def test_bar_ignore_index(self): ax = df.plot.bar(use_index=False, ax=ax) self._check_text_labels(ax.get_xticklabels(), ["0", "1", "2", "3"]) - @pytest.mark.parametrize("kw", ["c", "color"]) - def test_bar_user_colors(self, kw): + def test_bar_user_colors(self): s = Series([1, 2, 3, 4]) expected = [ @@ -279,7 +278,7 @@ def test_bar_user_colors(self, kw): (1.0, 0.0, 0.0, 1.0), ] - ax = s.plot.bar(**{kw: ["red", "blue", "blue", "red"]}) + ax = s.plot.bar(color=["red", "blue", "blue", "red"]) result = [p.get_facecolor() for p in ax.patches] assert result == expected From f7b833c84e66a0bf024203fad30fa24edc18d9a6 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Tue, 25 Jan 2022 15:30:53 +0100 Subject: [PATCH 14/22] make changes minimal --- pandas/tests/plotting/frame/test_frame.py | 1 - pandas/tests/plotting/frame/test_frame_color.py | 6 +++--- pandas/tests/plotting/test_series.py | 6 ++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 29a698c2c1af5..3370d46ff29f0 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -831,7 +831,6 @@ def test_plot_bar(self): _check_plot_works(df.plot.bar) df = DataFrame({"a": [0, 1], "b": [1, 0]}) - ax = _check_plot_works(df.plot.bar) self._check_ticks_props(ax, xrot=90) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index ff3792d448520..cdc135cddd524 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -119,7 +119,7 @@ def test_bar_colors(self): tm.close() custom_colors = "rgcby" - ax = df.plot.bar(color="rgcby") + ax = df.plot.bar(color=custom_colors) self._check_colors(ax.patches[::5], facecolors=custom_colors) tm.close() @@ -151,14 +151,14 @@ def test_bar_user_colors(self): ) # This should *only* work when `y` is specified, else # we use one color per column + ax = df.plot.bar(y="A", color=df["color"]) + result = [p.get_facecolor() for p in ax.patches] expected = [ (1.0, 0.0, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.0, 1.0), ] - ax = df.plot.bar(y="A", color=df["color"]) - result = [p.get_facecolor() for p in ax.patches] assert result == expected def test_if_scatterplot_colorbar_affects_xaxis_visibility(self): diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 5745a2890cefa..44fc6042ebaab 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -270,16 +270,14 @@ def test_bar_ignore_index(self): def test_bar_user_colors(self): s = Series([1, 2, 3, 4]) - + ax = s.plot.bar(color=["red", "blue", "blue", "red"]) + result = [p.get_facecolor() for p in ax.patches] expected = [ (1.0, 0.0, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.0, 1.0), ] - - ax = s.plot.bar(color=["red", "blue", "blue", "red"]) - result = [p.get_facecolor() for p in ax.patches] assert result == expected def test_rotation(self): From f99424e1bad253acdd6c200b472507392cef497d Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Thu, 27 Jan 2022 15:55:41 +0100 Subject: [PATCH 15/22] add release notes --- doc/source/whatsnew/v1.4.1.rst | 56 ++++++++++++++++++++++++++++++++++ pandas/plotting/_core.py | 18 ++++++----- 2 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 doc/source/whatsnew/v1.4.1.rst diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst new file mode 100644 index 0000000000000..6f00b54106ddb --- /dev/null +++ b/doc/source/whatsnew/v1.4.1.rst @@ -0,0 +1,56 @@ +.. _whatsnew_141: + +What's new in 1.4.1 (February ??, 2022) +--------------------------------------- + +These are the changes in pandas 1.4.1. See :ref:`release` for a full changelog +including other versions of pandas. + +{{ header }} + +.. --------------------------------------------------------------------------- + +.. _whatsnew_141.regressions: + +Fixed regressions +~~~~~~~~~~~~~~~~~ +- Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`) +- Regression in :meth:`DataFrame.loc.__setitem__` losing :class:`Index` name if :class:`DataFrame` was empty before (:issue:`45621`) +- + +.. --------------------------------------------------------------------------- + +.. _whatsnew_141.bug_fixes: + +Bug fixes +~~~~~~~~~ +- Fixed segfault in :meth:``DataFrame.to_json`` when dumping tz-aware datetimes in Python 3.10 (:issue:`42130`) +- + +.. --------------------------------------------------------------------------- + +.. _whatsnew_141.plotting: + +Plotting +^^^^^^^^ +- The function :meth:`DataFrame.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`, :issue:`44856`) +- + +.. --------------------------------------------------------------------------- + +.. _whatsnew_141.other: + + +Other +~~~~~ +- Reverted performance speedup of :meth:`DataFrame.corr` for ``method=pearson`` to fix precision regression (:issue:`45640`, :issue:`42761`) +- + +.. --------------------------------------------------------------------------- + +.. _whatsnew_141.contributors: + +Contributors +~~~~~~~~~~~~ + +.. contributors:: v1.4.0..v1.4.1|HEAD diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index a4440a6e55db2..eadb1cd3cd6aa 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1614,6 +1614,11 @@ def scatter(self, x, y, s=None, c=None, **kwargs): .. versionchanged:: 1.1.0 + size : str, int or array-like, optional + The color of each point. Alias for `s`. + `s` and `size` aren't allowed at the same time. + .. versionadded:: 1.4.1 + c : str, int or array-like, optional The color of each point. Possible values are: @@ -1628,15 +1633,12 @@ def scatter(self, x, y, s=None, c=None, **kwargs): - A column name or position whose values will be used to color the marker points according to a colormap. + color : str, int or array-like, optional + The color of each point. Alias for `c`. + `c` and `color` aren't allowed at the same time. + .. versionadded:: 1.4.1 + **kwargs - size : str, int or array-like, optional - The color of each point. Alias for `s`. - `s` and `size` aren't allowed at the same time. - .. versionadded:: 1.4.1 - color : str, int or array-like, optional - The color of each point. Alias for `c`. - `c` and `color` aren't allowed at the same time. - .. versionadded:: 1.4.1 Keyword arguments to pass on to :meth:`DataFrame.plot`. Returns From abf377ed97236e7bdf25dd0149391943261b26cf Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Fri, 28 Jan 2022 10:39:49 +0100 Subject: [PATCH 16/22] add changes to _whatsnew_150 --- doc/source/whatsnew/v1.4.1.rst | 9 - doc/source/whatsnew/v1.5.0.rst | 340 +++++++++++++++++++++++++++++++++ pandas/plotting/_core.py | 16 +- 3 files changed, 344 insertions(+), 21 deletions(-) create mode 100644 doc/source/whatsnew/v1.5.0.rst diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 6f00b54106ddb..527e997f5d4db 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -29,15 +29,6 @@ Bug fixes .. --------------------------------------------------------------------------- -.. _whatsnew_141.plotting: - -Plotting -^^^^^^^^ -- The function :meth:`DataFrame.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`, :issue:`44856`) -- - -.. --------------------------------------------------------------------------- - .. _whatsnew_141.other: diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst new file mode 100644 index 0000000000000..a4d5a98cf34fd --- /dev/null +++ b/doc/source/whatsnew/v1.5.0.rst @@ -0,0 +1,340 @@ +.. _whatsnew_150: + +What's new in 1.5.0 (??) +------------------------ + +These are the changes in pandas 1.5.0. See :ref:`release` for a full changelog +including other versions of pandas. + +{{ header }} + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.enhancements: + +Enhancements +~~~~~~~~~~~~ + +.. _whatsnew_150.enhancements.styler: + +Styler +^^^^^^ + + - New method :meth:`.Styler.to_string` for alternative customisable output methods (:issue:`44502`) + - Various bug fixes, see below. + +.. _whatsnew_150.enhancements.enhancement2: + +enhancement2 +^^^^^^^^^^^^ + +.. _whatsnew_150.enhancements.other: + +Other enhancements +^^^^^^^^^^^^^^^^^^ +- :meth:`MultiIndex.to_frame` now supports the argument ``allow_duplicates`` and raises on duplicate labels if it is missing or False (:issue:`45245`) +- :class:`StringArray` now accepts array-likes containing nan-likes (``None``, ``np.nan``) for the ``values`` parameter in its constructor in addition to strings and :attr:`pandas.NA`. (:issue:`40839`) +- Improved the rendering of ``categories`` in :class:`CategoricalIndex` (:issue:`45218`) +- :meth:`to_numeric` now preserves float64 arrays when downcasting would generate values not representable in float32 (:issue:`43693`) +- :meth:`.GroupBy.min` and :meth:`.GroupBy.max` now supports `Numba `_ execution with the ``engine`` keyword (:issue:`45428`) +- + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.notable_bug_fixes: + +Notable bug fixes +~~~~~~~~~~~~~~~~~ + +These are bug fixes that might have notable behavior changes. + +.. _whatsnew_150.notable_bug_fixes.notable_bug_fix1: + +notable_bug_fix1 +^^^^^^^^^^^^^^^^ + +.. _whatsnew_150.notable_bug_fixes.notable_bug_fix2: + +notable_bug_fix2 +^^^^^^^^^^^^^^^^ + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.api_breaking: + +Backwards incompatible API changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. _whatsnew_150.api_breaking.deps: + +Increased minimum versions for dependencies +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Some minimum supported versions of dependencies were updated. +If installed, we now require: + ++-----------------+-----------------+----------+---------+ +| Package | Minimum Version | Required | Changed | ++=================+=================+==========+=========+ +| mypy (dev) | 0.931 | | X | ++-----------------+-----------------+----------+---------+ + + +For `optional libraries `_ the general recommendation is to use the latest version. +The following table lists the lowest version per library that is currently being tested throughout the development of pandas. +Optional libraries below the lowest tested version may still work, but are not considered supported. + ++-----------------+-----------------+---------+ +| Package | Minimum Version | Changed | ++=================+=================+=========+ +| | | X | ++-----------------+-----------------+---------+ + +See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more. + + +.. _whatsnew_150.read_xml_dtypes: + +read_xml now supports ``dtype``, ``converters``, and ``parse_dates`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Similar to other IO methods, :func:`pandas.read_xml` now supports assigning specific dtypes to columns, +apply converter methods, and parse dates (:issue:`43567`). + +.. ipython:: python + + xml_dates = """ + + + square + 00360 + 4.0 + 2020-01-01 + + + circle + 00360 + + 2021-01-01 + + + triangle + 00180 + 3.0 + 2022-01-01 + + """ + + df = pd.read_xml( + xml_dates, + dtype={'sides': 'Int64'}, + converters={'degrees': str}, + parse_dates=['date'] + ) + df + df.dtypes + +.. _whatsnew_150.api_breaking.other: + +Other API changes +^^^^^^^^^^^^^^^^^ +- +- + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.deprecations: + +Deprecations +~~~~~~~~~~~~ + +.. _whatsnew_150.deprecations.int_slicing_series: + +In a future version, integer slicing on a :class:`Series` with a :class:`Int64Index` or :class:`RangeIndex` will be treated as *label-based*, not positional. This will make the behavior consistent with other :meth:`Series.__getitem__` and :meth:`Series.__setitem__` behaviors (:issue:`45162`). + +For example: + +.. ipython:: python + + ser = pd.Series([1, 2, 3, 4, 5], index=[2, 3, 5, 7, 11]) + +In the old behavior, ``ser[2:4]`` treats the slice as positional: + +*Old behavior*: + +.. code-block:: ipython + + In [3]: ser[2:4] + Out[3]: + 5 3 + 7 4 + dtype: int64 + +In a future version, this will be treated as label-based: + +*Future behavior*: + +.. code-block:: ipython + + In [4]: ser.loc[2:4] + Out[4]: + 2 1 + 3 2 + dtype: int64 + +To retain the old behavior, use ``series.iloc[i:j]``. To get the future behavior, +use ``series.loc[i:j]``. + +Slicing on a :class:`DataFrame` will not be affected. + +.. _whatsnew_150.deprecations.other: + +Other Deprecations +^^^^^^^^^^^^^^^^^^ +- Deprecated the keyword ``line_terminator`` in :meth:`DataFrame.to_csv` and :meth:`Series.to_csv`, use ``lineterminator`` instead; this is for consistency with :func:`read_csv` and the standard library 'csv' module (:issue:`9568`) +- Deprecated behavior of :meth:`SparseArray.astype`, :meth:`Series.astype`, and :meth:`DataFrame.astype` with :class:`SparseDtype` when passing a non-sparse ``dtype``. In a future version, this will cast to that non-sparse dtype instead of wrapping it in a :class:`SparseDtype` (:issue:`34457`) +- Deprecated behavior of :meth:`DatetimeIndex.intersection` and :meth:`DatetimeIndex.symmetric_difference` (``union`` behavior was already deprecated in version 1.3.0) with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`, :issue:`45357`) +- Deprecated :meth:`DataFrame.iteritems`, :meth:`Series.iteritems`, :meth:`HDFStore.iteritems` in favor of :meth:`DataFrame.items`, :meth:`Series.items`, :meth:`HDFStore.items` (:issue:`45321`) +- Deprecated :meth:`Series.is_monotonic` and :meth:`Index.is_monotonic` in favor of :meth:`Series.is_monotonic_increasing` and :meth:`Index.is_monotonic_increasing` (:issue:`45422`, :issue:`21335`) +- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`) +- + + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.performance: + +Performance improvements +~~~~~~~~~~~~~~~~~~~~~~~~ +- Performance improvement in :meth:`.GroupBy.transform` for some user-defined DataFrame -> Series functions (:issue:`45387`) +- Performance improvement in :meth:`DataFrame.duplicated` when subset consists of only one column (:issue:`45236`) +- + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.bug_fixes: + +Bug fixes +~~~~~~~~~ + +Categorical +^^^^^^^^^^^ +- Bug in :meth:`CategoricalIndex.union` when the index's categories are integer-dtype and the index contains ``NaN`` values incorrectly raising instead of casting to ``float64`` (:issue:`45362`) +- + +Datetimelike +^^^^^^^^^^^^ +- Bug in :meth:`DataFrame.quantile` with datetime-like dtypes and no rows incorrectly returning ``float64`` dtype instead of retaining datetime-like dtype (:issue:`41544`) +- Bug in :func:`to_datetime` with sequences of ``np.str_`` objects incorrectly raising (:issue:`32264`) +- Bug in :class:`Timestamp` construction when passing datetime components as positional arguments and ``tzinfo`` as a keyword argument incorrectly raising (:issue:`31929`) +- + +Timedelta +^^^^^^^^^ +- + +Timezones +^^^^^^^^^ +- +- + +Numeric +^^^^^^^ +- Bug in operations with array-likes with ``dtype="boolean"`` and :attr:`NA` incorrectly altering the array in-place (:issue:`45421`) +- + +Conversion +^^^^^^^^^^ +- Bug in :meth:`DataFrame.astype` not preserving subclasses (:issue:`40810`) +- Bug in constructing a :class:`Series` from a float-containing list or a floating-dtype ndarray-like (e.g. ``dask.Array``) and an integer dtype raising instead of casting like we would with an ``np.ndarray`` (:issue:`40110`) +- Bug in :meth:`Float64Index.astype` to unsigned integer dtype incorrectly casting to ``np.int64`` dtype (:issue:`45309`) +- Bug in :meth:`Series.astype` and :meth:`DataFrame.astype` from floating dtype to unsigned integer dtype failing to raise in the presence of negative values (:issue:`45151`) +- Bug in :func:`array` with ``FloatingDtype`` and values containing float-castable strings incorrectly raising (:issue:`45424`) +- + +Strings +^^^^^^^ +- +- + +Interval +^^^^^^^^ +- Bug in :meth:`IntervalArray.__setitem__` when setting ``np.nan`` into an integer-backed array raising ``ValueError`` instead of ``TypeError`` (:issue:`45484`) +- + +Indexing +^^^^^^^^ +- Bug in :meth:`loc.__getitem__` with a list of keys causing an internal inconsistency that could lead to a disconnect between ``frame.at[x, y]`` vs ``frame[y].loc[x]`` (:issue:`22372`) +- Bug in :meth:`DataFrame.iloc` where indexing a single row on a :class:`DataFrame` with a single ExtensionDtype column gave a copy instead of a view on the underlying data (:issue:`45241`) +- Bug in :meth:`Series.__setitem__` with a non-integer :class:`Index` when using an integer key to set a value that cannot be set inplace where a ``ValueError`` was raised insead of casting to a common dtype (:issue:`45070`) +- Bug when setting a value too large for a :class:`Series` dtype failing to coerce to a common type (:issue:`26049`, :issue:`32878`) +- Bug in :meth:`loc.__setitem__` treating ``range`` keys as positional instead of label-based (:issue:`45479`) +- Bug in :meth:`Series.__setitem__` when setting ``boolean`` dtype values containing ``NA`` incorrectly raising instead of casting to ``boolean`` dtype (:issue:`45462`) +- Bug in :meth:`Series.__setitem__` where setting :attr:`NA` into a numeric-dtpye :class:`Series` would incorrectly upcast to object-dtype rather than treating the value as ``np.nan`` (:issue:`44199`) +- Bug in getting a column from a DataFrame with an object-dtype row index with datetime-like values: the resulting Series now preserves the exact object-dtype Index from the parent DataFrame (:issue:`42950`) +- + +Missing +^^^^^^^ +- +- + +MultiIndex +^^^^^^^^^^ +- +- + +I/O +^^^ +- Bug in :meth:`DataFrame.to_stata` where no error is raised if the :class:`DataFrame` contains ``-np.inf`` (:issue:`45350`) +- Bug in :meth:`DataFrame.info` where a new line at the end of the output is omitted when called on an empty :class:`DataFrame` (:issue:`45494`) +- Bug in :func:`read_parquet` when ``engine="pyarrow"`` which caused partial write to disk when column of unsupported datatype was passed (:issue:`44914`) +- + +Period +^^^^^^ +- +- + +Plotting +^^^^^^^^ +- Bug in :meth:`DataFrame.plot.barh` that prevented labeling the x-axis and ``xlabel`` updating the y-axis label (:issue:`45144`) +- Bug in :meth:`DataFrame.plot.box` that prevented labeling the x-axis (:issue:`45463`) +- Bug in :meth:`DataFrame.boxplot` that prevented passing in ``xlabel`` and ``ylabel`` (:issue:`45463`) +- Bug in :meth:`DataFrame.boxplot` that prevented specifying ``vert=False`` (:issue:`36918`) +- The function :meth:`DataFrame.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`) +- + +Groupby/resample/rolling +^^^^^^^^^^^^^^^^^^^^^^^^ +- Bug in :meth:`DataFrame.resample` ignoring ``closed="right"`` on :class:`TimedeltaIndex` (:issue:`45414`) +- + +Reshaping +^^^^^^^^^ +- Bug in :func:`concat` between a :class:`Series` with integer dtype and another with :class:`CategoricalDtype` with integer categories and containing ``NaN`` values casting to object dtype instead of ``float64`` (:issue:`45359`) +- + +Sparse +^^^^^^ +- +- + +ExtensionArray +^^^^^^^^^^^^^^ +- Bug in :meth:`IntegerArray.searchsorted` and :meth:`FloatingArray.searchsorted` returning inconsistent results when acting on ``np.nan`` (:issue:`45255`) +- + +Styler +^^^^^^ +- Minor bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`) +- + +Other +^^^^^ +- Bug in :meth:`Series.asof` and :meth:`DataFrame.asof` incorrectly casting bool-dtype results to ``float64`` dtype (:issue:`16063`) +- + +.. ***DO NOT USE THIS SECTION*** + +- +- + +.. --------------------------------------------------------------------------- +.. _whatsnew_150.contributors: + +Contributors +~~~~~~~~~~~~ diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index eadb1cd3cd6aa..baba4e2bae253 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1602,7 +1602,8 @@ def scatter(self, x, y, s=None, c=None, **kwargs): The column name or column position to be used as vertical coordinates for each point. s : str, scalar or array-like, optional - The size of each point. Possible values are: + The size of each point. ``size`` is also accepted as an alternate keyword + argument for ``s`` for consistency with other methods. Possible values are: - A string with the name of the column to be used for marker's size. @@ -1614,13 +1615,9 @@ def scatter(self, x, y, s=None, c=None, **kwargs): .. versionchanged:: 1.1.0 - size : str, int or array-like, optional - The color of each point. Alias for `s`. - `s` and `size` aren't allowed at the same time. - .. versionadded:: 1.4.1 - c : str, int or array-like, optional - The color of each point. Possible values are: + The color of each point. ``color`` is also accepted as an alternate keyword + argument for ``c`` for consistency with other methods. Possible values are: - A single color string referred to by name, RGB or RGBA code, for instance 'red' or '#a98d19'. @@ -1633,11 +1630,6 @@ def scatter(self, x, y, s=None, c=None, **kwargs): - A column name or position whose values will be used to color the marker points according to a colormap. - color : str, int or array-like, optional - The color of each point. Alias for `c`. - `c` and `color` aren't allowed at the same time. - .. versionadded:: 1.4.1 - **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. From 33c1ca50f044e00be240ba77c1049beb015c8f8d Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Mon, 7 Mar 2022 12:00:14 +0100 Subject: [PATCH 17/22] Revert 'add changes to _whatsnew_150' This reverts commit abf377ed97236e7bdf25dd0149391943261b26cf --- doc/source/whatsnew/v1.4.1.rst | 9 + doc/source/whatsnew/v1.5.0.rst | 340 --------------------------------- pandas/plotting/_core.py | 16 +- 3 files changed, 21 insertions(+), 344 deletions(-) delete mode 100644 doc/source/whatsnew/v1.5.0.rst diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 527e997f5d4db..6f00b54106ddb 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -29,6 +29,15 @@ Bug fixes .. --------------------------------------------------------------------------- +.. _whatsnew_141.plotting: + +Plotting +^^^^^^^^ +- The function :meth:`DataFrame.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`, :issue:`44856`) +- + +.. --------------------------------------------------------------------------- + .. _whatsnew_141.other: diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst deleted file mode 100644 index a4d5a98cf34fd..0000000000000 --- a/doc/source/whatsnew/v1.5.0.rst +++ /dev/null @@ -1,340 +0,0 @@ -.. _whatsnew_150: - -What's new in 1.5.0 (??) ------------------------- - -These are the changes in pandas 1.5.0. See :ref:`release` for a full changelog -including other versions of pandas. - -{{ header }} - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.enhancements: - -Enhancements -~~~~~~~~~~~~ - -.. _whatsnew_150.enhancements.styler: - -Styler -^^^^^^ - - - New method :meth:`.Styler.to_string` for alternative customisable output methods (:issue:`44502`) - - Various bug fixes, see below. - -.. _whatsnew_150.enhancements.enhancement2: - -enhancement2 -^^^^^^^^^^^^ - -.. _whatsnew_150.enhancements.other: - -Other enhancements -^^^^^^^^^^^^^^^^^^ -- :meth:`MultiIndex.to_frame` now supports the argument ``allow_duplicates`` and raises on duplicate labels if it is missing or False (:issue:`45245`) -- :class:`StringArray` now accepts array-likes containing nan-likes (``None``, ``np.nan``) for the ``values`` parameter in its constructor in addition to strings and :attr:`pandas.NA`. (:issue:`40839`) -- Improved the rendering of ``categories`` in :class:`CategoricalIndex` (:issue:`45218`) -- :meth:`to_numeric` now preserves float64 arrays when downcasting would generate values not representable in float32 (:issue:`43693`) -- :meth:`.GroupBy.min` and :meth:`.GroupBy.max` now supports `Numba `_ execution with the ``engine`` keyword (:issue:`45428`) -- - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.notable_bug_fixes: - -Notable bug fixes -~~~~~~~~~~~~~~~~~ - -These are bug fixes that might have notable behavior changes. - -.. _whatsnew_150.notable_bug_fixes.notable_bug_fix1: - -notable_bug_fix1 -^^^^^^^^^^^^^^^^ - -.. _whatsnew_150.notable_bug_fixes.notable_bug_fix2: - -notable_bug_fix2 -^^^^^^^^^^^^^^^^ - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.api_breaking: - -Backwards incompatible API changes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. _whatsnew_150.api_breaking.deps: - -Increased minimum versions for dependencies -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Some minimum supported versions of dependencies were updated. -If installed, we now require: - -+-----------------+-----------------+----------+---------+ -| Package | Minimum Version | Required | Changed | -+=================+=================+==========+=========+ -| mypy (dev) | 0.931 | | X | -+-----------------+-----------------+----------+---------+ - - -For `optional libraries `_ the general recommendation is to use the latest version. -The following table lists the lowest version per library that is currently being tested throughout the development of pandas. -Optional libraries below the lowest tested version may still work, but are not considered supported. - -+-----------------+-----------------+---------+ -| Package | Minimum Version | Changed | -+=================+=================+=========+ -| | | X | -+-----------------+-----------------+---------+ - -See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more. - - -.. _whatsnew_150.read_xml_dtypes: - -read_xml now supports ``dtype``, ``converters``, and ``parse_dates`` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Similar to other IO methods, :func:`pandas.read_xml` now supports assigning specific dtypes to columns, -apply converter methods, and parse dates (:issue:`43567`). - -.. ipython:: python - - xml_dates = """ - - - square - 00360 - 4.0 - 2020-01-01 - - - circle - 00360 - - 2021-01-01 - - - triangle - 00180 - 3.0 - 2022-01-01 - - """ - - df = pd.read_xml( - xml_dates, - dtype={'sides': 'Int64'}, - converters={'degrees': str}, - parse_dates=['date'] - ) - df - df.dtypes - -.. _whatsnew_150.api_breaking.other: - -Other API changes -^^^^^^^^^^^^^^^^^ -- -- - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.deprecations: - -Deprecations -~~~~~~~~~~~~ - -.. _whatsnew_150.deprecations.int_slicing_series: - -In a future version, integer slicing on a :class:`Series` with a :class:`Int64Index` or :class:`RangeIndex` will be treated as *label-based*, not positional. This will make the behavior consistent with other :meth:`Series.__getitem__` and :meth:`Series.__setitem__` behaviors (:issue:`45162`). - -For example: - -.. ipython:: python - - ser = pd.Series([1, 2, 3, 4, 5], index=[2, 3, 5, 7, 11]) - -In the old behavior, ``ser[2:4]`` treats the slice as positional: - -*Old behavior*: - -.. code-block:: ipython - - In [3]: ser[2:4] - Out[3]: - 5 3 - 7 4 - dtype: int64 - -In a future version, this will be treated as label-based: - -*Future behavior*: - -.. code-block:: ipython - - In [4]: ser.loc[2:4] - Out[4]: - 2 1 - 3 2 - dtype: int64 - -To retain the old behavior, use ``series.iloc[i:j]``. To get the future behavior, -use ``series.loc[i:j]``. - -Slicing on a :class:`DataFrame` will not be affected. - -.. _whatsnew_150.deprecations.other: - -Other Deprecations -^^^^^^^^^^^^^^^^^^ -- Deprecated the keyword ``line_terminator`` in :meth:`DataFrame.to_csv` and :meth:`Series.to_csv`, use ``lineterminator`` instead; this is for consistency with :func:`read_csv` and the standard library 'csv' module (:issue:`9568`) -- Deprecated behavior of :meth:`SparseArray.astype`, :meth:`Series.astype`, and :meth:`DataFrame.astype` with :class:`SparseDtype` when passing a non-sparse ``dtype``. In a future version, this will cast to that non-sparse dtype instead of wrapping it in a :class:`SparseDtype` (:issue:`34457`) -- Deprecated behavior of :meth:`DatetimeIndex.intersection` and :meth:`DatetimeIndex.symmetric_difference` (``union`` behavior was already deprecated in version 1.3.0) with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`, :issue:`45357`) -- Deprecated :meth:`DataFrame.iteritems`, :meth:`Series.iteritems`, :meth:`HDFStore.iteritems` in favor of :meth:`DataFrame.items`, :meth:`Series.items`, :meth:`HDFStore.items` (:issue:`45321`) -- Deprecated :meth:`Series.is_monotonic` and :meth:`Index.is_monotonic` in favor of :meth:`Series.is_monotonic_increasing` and :meth:`Index.is_monotonic_increasing` (:issue:`45422`, :issue:`21335`) -- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`) -- - - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.performance: - -Performance improvements -~~~~~~~~~~~~~~~~~~~~~~~~ -- Performance improvement in :meth:`.GroupBy.transform` for some user-defined DataFrame -> Series functions (:issue:`45387`) -- Performance improvement in :meth:`DataFrame.duplicated` when subset consists of only one column (:issue:`45236`) -- - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.bug_fixes: - -Bug fixes -~~~~~~~~~ - -Categorical -^^^^^^^^^^^ -- Bug in :meth:`CategoricalIndex.union` when the index's categories are integer-dtype and the index contains ``NaN`` values incorrectly raising instead of casting to ``float64`` (:issue:`45362`) -- - -Datetimelike -^^^^^^^^^^^^ -- Bug in :meth:`DataFrame.quantile` with datetime-like dtypes and no rows incorrectly returning ``float64`` dtype instead of retaining datetime-like dtype (:issue:`41544`) -- Bug in :func:`to_datetime` with sequences of ``np.str_`` objects incorrectly raising (:issue:`32264`) -- Bug in :class:`Timestamp` construction when passing datetime components as positional arguments and ``tzinfo`` as a keyword argument incorrectly raising (:issue:`31929`) -- - -Timedelta -^^^^^^^^^ -- - -Timezones -^^^^^^^^^ -- -- - -Numeric -^^^^^^^ -- Bug in operations with array-likes with ``dtype="boolean"`` and :attr:`NA` incorrectly altering the array in-place (:issue:`45421`) -- - -Conversion -^^^^^^^^^^ -- Bug in :meth:`DataFrame.astype` not preserving subclasses (:issue:`40810`) -- Bug in constructing a :class:`Series` from a float-containing list or a floating-dtype ndarray-like (e.g. ``dask.Array``) and an integer dtype raising instead of casting like we would with an ``np.ndarray`` (:issue:`40110`) -- Bug in :meth:`Float64Index.astype` to unsigned integer dtype incorrectly casting to ``np.int64`` dtype (:issue:`45309`) -- Bug in :meth:`Series.astype` and :meth:`DataFrame.astype` from floating dtype to unsigned integer dtype failing to raise in the presence of negative values (:issue:`45151`) -- Bug in :func:`array` with ``FloatingDtype`` and values containing float-castable strings incorrectly raising (:issue:`45424`) -- - -Strings -^^^^^^^ -- -- - -Interval -^^^^^^^^ -- Bug in :meth:`IntervalArray.__setitem__` when setting ``np.nan`` into an integer-backed array raising ``ValueError`` instead of ``TypeError`` (:issue:`45484`) -- - -Indexing -^^^^^^^^ -- Bug in :meth:`loc.__getitem__` with a list of keys causing an internal inconsistency that could lead to a disconnect between ``frame.at[x, y]`` vs ``frame[y].loc[x]`` (:issue:`22372`) -- Bug in :meth:`DataFrame.iloc` where indexing a single row on a :class:`DataFrame` with a single ExtensionDtype column gave a copy instead of a view on the underlying data (:issue:`45241`) -- Bug in :meth:`Series.__setitem__` with a non-integer :class:`Index` when using an integer key to set a value that cannot be set inplace where a ``ValueError`` was raised insead of casting to a common dtype (:issue:`45070`) -- Bug when setting a value too large for a :class:`Series` dtype failing to coerce to a common type (:issue:`26049`, :issue:`32878`) -- Bug in :meth:`loc.__setitem__` treating ``range`` keys as positional instead of label-based (:issue:`45479`) -- Bug in :meth:`Series.__setitem__` when setting ``boolean`` dtype values containing ``NA`` incorrectly raising instead of casting to ``boolean`` dtype (:issue:`45462`) -- Bug in :meth:`Series.__setitem__` where setting :attr:`NA` into a numeric-dtpye :class:`Series` would incorrectly upcast to object-dtype rather than treating the value as ``np.nan`` (:issue:`44199`) -- Bug in getting a column from a DataFrame with an object-dtype row index with datetime-like values: the resulting Series now preserves the exact object-dtype Index from the parent DataFrame (:issue:`42950`) -- - -Missing -^^^^^^^ -- -- - -MultiIndex -^^^^^^^^^^ -- -- - -I/O -^^^ -- Bug in :meth:`DataFrame.to_stata` where no error is raised if the :class:`DataFrame` contains ``-np.inf`` (:issue:`45350`) -- Bug in :meth:`DataFrame.info` where a new line at the end of the output is omitted when called on an empty :class:`DataFrame` (:issue:`45494`) -- Bug in :func:`read_parquet` when ``engine="pyarrow"`` which caused partial write to disk when column of unsupported datatype was passed (:issue:`44914`) -- - -Period -^^^^^^ -- -- - -Plotting -^^^^^^^^ -- Bug in :meth:`DataFrame.plot.barh` that prevented labeling the x-axis and ``xlabel`` updating the y-axis label (:issue:`45144`) -- Bug in :meth:`DataFrame.plot.box` that prevented labeling the x-axis (:issue:`45463`) -- Bug in :meth:`DataFrame.boxplot` that prevented passing in ``xlabel`` and ``ylabel`` (:issue:`45463`) -- Bug in :meth:`DataFrame.boxplot` that prevented specifying ``vert=False`` (:issue:`36918`) -- The function :meth:`DataFrame.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`) -- - -Groupby/resample/rolling -^^^^^^^^^^^^^^^^^^^^^^^^ -- Bug in :meth:`DataFrame.resample` ignoring ``closed="right"`` on :class:`TimedeltaIndex` (:issue:`45414`) -- - -Reshaping -^^^^^^^^^ -- Bug in :func:`concat` between a :class:`Series` with integer dtype and another with :class:`CategoricalDtype` with integer categories and containing ``NaN`` values casting to object dtype instead of ``float64`` (:issue:`45359`) -- - -Sparse -^^^^^^ -- -- - -ExtensionArray -^^^^^^^^^^^^^^ -- Bug in :meth:`IntegerArray.searchsorted` and :meth:`FloatingArray.searchsorted` returning inconsistent results when acting on ``np.nan`` (:issue:`45255`) -- - -Styler -^^^^^^ -- Minor bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`) -- - -Other -^^^^^ -- Bug in :meth:`Series.asof` and :meth:`DataFrame.asof` incorrectly casting bool-dtype results to ``float64`` dtype (:issue:`16063`) -- - -.. ***DO NOT USE THIS SECTION*** - -- -- - -.. --------------------------------------------------------------------------- -.. _whatsnew_150.contributors: - -Contributors -~~~~~~~~~~~~ diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index baba4e2bae253..eadb1cd3cd6aa 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1602,8 +1602,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): The column name or column position to be used as vertical coordinates for each point. s : str, scalar or array-like, optional - The size of each point. ``size`` is also accepted as an alternate keyword - argument for ``s`` for consistency with other methods. Possible values are: + The size of each point. Possible values are: - A string with the name of the column to be used for marker's size. @@ -1615,9 +1614,13 @@ def scatter(self, x, y, s=None, c=None, **kwargs): .. versionchanged:: 1.1.0 + size : str, int or array-like, optional + The color of each point. Alias for `s`. + `s` and `size` aren't allowed at the same time. + .. versionadded:: 1.4.1 + c : str, int or array-like, optional - The color of each point. ``color`` is also accepted as an alternate keyword - argument for ``c`` for consistency with other methods. Possible values are: + The color of each point. Possible values are: - A single color string referred to by name, RGB or RGBA code, for instance 'red' or '#a98d19'. @@ -1630,6 +1633,11 @@ def scatter(self, x, y, s=None, c=None, **kwargs): - A column name or position whose values will be used to color the marker points according to a colormap. + color : str, int or array-like, optional + The color of each point. Alias for `c`. + `c` and `color` aren't allowed at the same time. + .. versionadded:: 1.4.1 + **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. From e6ac538075bb6adfda9a09ca4d034b3f80be8a7c Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:12:27 +0100 Subject: [PATCH 18/22] Update v1.4.1.rst --- doc/source/whatsnew/v1.4.1.rst | 7 ------- 1 file changed, 7 deletions(-) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 8705980c0e5fa..43a1ea812cc68 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -1,7 +1,6 @@ .. _whatsnew_141: What's new in 1.4.1 (February 12, 2022) - --------------------------------------- These are the changes in pandas 1.4.1. See :ref:`release` for a full changelog @@ -26,7 +25,6 @@ Fixed regressions - Regression in :func:`read_sql` with a DBAPI2 connection that is not an instance of ``sqlite3.Connection`` incorrectly requiring SQLAlchemy be installed (:issue:`45660`) - Regression in :class:`DateOffset` when constructing with an integer argument with no keywords (e.g. ``pd.DateOffset(n)``) would behave like ``datetime.timedelta(days=0)`` (:issue:`45643`, :issue:`45890`) - .. --------------------------------------------------------------------------- .. _whatsnew_141.bug_fixes: @@ -39,17 +37,14 @@ Bug fixes - Fixed builtin highlighters in :class:`.Styler` to be responsive to ``NA`` with nullable dtypes (:issue:`45804`) - Bug in :meth:`~Rolling.apply` with ``axis=1`` raising an erroneous ``ValueError`` (:issue:`45912`) - .. --------------------------------------------------------------------------- .. _whatsnew_141.other: - Other ~~~~~ - Reverted performance speedup of :meth:`DataFrame.corr` for ``method=pearson`` to fix precision regression (:issue:`45640`, :issue:`42761`) - .. --------------------------------------------------------------------------- .. _whatsnew_141.contributors: @@ -57,6 +52,4 @@ Other Contributors ~~~~~~~~~~~~ - .. contributors:: v1.4.0..v1.4.1 - From c9d6043c4328607f0c3562c626462cfdad4a5e35 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:13:40 +0100 Subject: [PATCH 19/22] Update v1.4.1.rst --- doc/source/whatsnew/v1.4.1.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 43a1ea812cc68..dd2002bb87648 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -14,6 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ +- Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`) - Regression in :func:`.assert_frame_equal` not respecting ``check_flags=False`` (:issue:`45554`) - Regression in :meth:`DataFrame.loc` raising ``ValueError`` when indexing (getting values) on a :class:`MultiIndex` with one level (:issue:`45779`) - Regression in :meth:`Series.fillna` with ``downcast=False`` incorrectly downcasting ``object`` dtype (:issue:`45603`) From 757f292d13c3da1d43d2dab59188ca4e530c36b3 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber Date: Mon, 7 Mar 2022 13:10:46 +0100 Subject: [PATCH 20/22] update v1.5.0.rst --- doc/source/whatsnew/v1.5.0.rst | 1 + pandas/plotting/_core.py | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 18fd1057c9b65..c900f3808fe03 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -422,6 +422,7 @@ Plotting - Bug in :meth:`DataFrame.boxplot` that prevented passing in ``xlabel`` and ``ylabel`` (:issue:`45463`) - Bug in :meth:`DataFrame.boxplot` that prevented specifying ``vert=False`` (:issue:`36918`) - Bug in :meth:`DataFrame.plot.scatter` that prevented specifying ``norm`` (:issue:`45809`) +- The function :meth:`DataFrame.plot.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44856`) Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 110a8636208b2..4d698fb0beb56 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1603,7 +1603,8 @@ def scatter(self, x, y, s=None, c=None, **kwargs): The column name or column position to be used as vertical coordinates for each point. s : str, scalar or array-like, optional - The size of each point. Possible values are: + The size of each point. ``size`` is also accepted as an alternate keyword + argument for ``s`` for consistency with other methods. Possible values are: - A string with the name of the column to be used for marker's size. @@ -1613,15 +1614,11 @@ def scatter(self, x, y, s=None, c=None, **kwargs): recursively. For instance, when passing [2,14] all points size will be either 2 or 14, alternatively. - .. versionchanged:: 1.1.0 - - size : str, int or array-like, optional - The color of each point. Alias for `s`. - `s` and `size` aren't allowed at the same time. - .. versionadded:: 1.4.1 + .. versionchanged:: 1.5.0 c : str, int or array-like, optional - The color of each point. Possible values are: + The color of each point. ``color`` is also accepted as an alternate keyword + argument for ``c`` for consistency with other methods. Possible values are: - A single color string referred to by name, RGB or RGBA code, for instance 'red' or '#a98d19'. @@ -1634,10 +1631,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): - A column name or position whose values will be used to color the marker points according to a colormap. - color : str, int or array-like, optional - The color of each point. Alias for `c`. - `c` and `color` aren't allowed at the same time. - .. versionadded:: 1.4.1 + .. versionchanged:: 1.5.0 **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. From 53503ce78efe57fc7efc2b250e626e305b3a1829 Mon Sep 17 00:00:00 2001 From: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> Date: Mon, 7 Mar 2022 13:15:22 +0100 Subject: [PATCH 21/22] update issue number --- doc/source/whatsnew/v1.5.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index c900f3808fe03..f91ea1e28e71f 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -422,7 +422,7 @@ Plotting - Bug in :meth:`DataFrame.boxplot` that prevented passing in ``xlabel`` and ``ylabel`` (:issue:`45463`) - Bug in :meth:`DataFrame.boxplot` that prevented specifying ``vert=False`` (:issue:`36918`) - Bug in :meth:`DataFrame.plot.scatter` that prevented specifying ``norm`` (:issue:`45809`) -- The function :meth:`DataFrame.plot.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44856`) +- The function :meth:`DataFrame.plot.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`) Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ From 73e3fb176c617e1159cce0caba64bacb1df8dfb5 Mon Sep 17 00:00:00 2001 From: ifesca research team Date: Tue, 8 Mar 2022 11:48:46 +0100 Subject: [PATCH 22/22] add alias do docstring like in read_csv --- pandas/plotting/_core.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 4d698fb0beb56..6a6555df96df4 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1603,8 +1603,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): The column name or column position to be used as vertical coordinates for each point. s : str, scalar or array-like, optional - The size of each point. ``size`` is also accepted as an alternate keyword - argument for ``s`` for consistency with other methods. Possible values are: + The size of each point. Possible values are: - A string with the name of the column to be used for marker's size. @@ -1614,11 +1613,15 @@ def scatter(self, x, y, s=None, c=None, **kwargs): recursively. For instance, when passing [2,14] all points size will be either 2 or 14, alternatively. - .. versionchanged:: 1.5.0 + .. versionchanged:: 1.1.0 + + size : str, scalar or array-like, optional + Alias for s. + + .. versionadded:: 1.5.0 c : str, int or array-like, optional - The color of each point. ``color`` is also accepted as an alternate keyword - argument for ``c`` for consistency with other methods. Possible values are: + The color of each point. Possible values are: - A single color string referred to by name, RGB or RGBA code, for instance 'red' or '#a98d19'. @@ -1630,8 +1633,10 @@ def scatter(self, x, y, s=None, c=None, **kwargs): - A column name or position whose values will be used to color the marker points according to a colormap. + color : str, int or array-like, optional + Alias for c. - .. versionchanged:: 1.5.0 + .. versionadded:: 1.5.0 **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`.