From 8f2e9bc2d92efb8e1a8e0d384bed3e7d45f2f36b Mon Sep 17 00:00:00 2001 From: Thomas Lazarus Date: Tue, 14 Nov 2023 19:33:06 -0600 Subject: [PATCH 1/3] Updates to check the dtypes instead --- pandas/plotting/_matplotlib/core.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 76b68c6b03dd2..8010691421e8f 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -908,7 +908,9 @@ def plt(self): @final def _get_xticks(self): index = self.data.index - is_datetype = index.inferred_type in ("datetime", "date", "datetime64", "time") + is_datetype = self.data.dtypes.isin( + ["datetime64[ns]", "datetime", "date", "time"] + ).any() # TODO: be stricter about x? x: list[int] | np.ndarray @@ -1238,9 +1240,9 @@ def __init__(self, data, x, y, **kwargs) -> None: MPLPlot.__init__(self, data, **kwargs) if x is None or y is None: raise ValueError(self._kind + " requires an x and y column") - if is_integer(x) and not self.data.columns._holds_integer(): + if is_integer(x) and not (self.data.dtypes == "int").any(): x = self.data.columns[x] - if is_integer(y) and not self.data.columns._holds_integer(): + if is_integer(y) and not (self.data.dtypes == "int").any(): y = self.data.columns[y] self.x = x @@ -1308,7 +1310,7 @@ def __init__( self.norm = norm super().__init__(data, x, y, **kwargs) - if is_integer(c) and not self.data.columns._holds_integer(): + if is_integer(c) and not (self.data.dtypes == "int").any(): c = self.data.columns[c] self.c = c @@ -1424,7 +1426,7 @@ def _kind(self) -> Literal["hexbin"]: def __init__(self, data, x, y, C=None, *, colorbar: bool = True, **kwargs) -> None: super().__init__(data, x, y, **kwargs) - if is_integer(C) and not self.data.columns._holds_integer(): + if is_integer(C) and not (self.data.dtypes == "int").any(): C = self.data.columns[C] self.C = C From f311b64fd3c060e4360254b832a7a7b1b3d14049 Mon Sep 17 00:00:00 2001 From: Thomas Lazarus Date: Thu, 16 Nov 2023 19:51:38 -0600 Subject: [PATCH 2/3] Switches to using is_integer_dtype() --- pandas/plotting/_matplotlib/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index b29c62769468a..ab5f093652de3 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1250,9 +1250,9 @@ def __init__(self, data, x, y, **kwargs) -> None: MPLPlot.__init__(self, data, **kwargs) if x is None or y is None: raise ValueError(self._kind + " requires an x and y column") - if is_integer(x) and not (self.data.dtypes == "int").any(): + if is_integer(x) and not is_integer_dtype(self.data.columns): x = self.data.columns[x] - if is_integer(y) and not (self.data.dtypes == "int").any(): + if is_integer(y) and not is_integer_dtype(self.data.columns): y = self.data.columns[y] self.x = x @@ -1322,7 +1322,7 @@ def __init__( self.norm = norm super().__init__(data, x, y, **kwargs) - if is_integer(c) and not (self.data.dtypes == "int").any(): + if is_integer(c) and not is_integer_dtype(self.data.columns): c = self.data.columns[c] self.c = c @@ -1438,7 +1438,7 @@ def _kind(self) -> Literal["hexbin"]: def __init__(self, data, x, y, C=None, *, colorbar: bool = True, **kwargs) -> None: super().__init__(data, x, y, **kwargs) - if is_integer(C) and not (self.data.dtypes == "int").any(): + if is_integer(C) and not is_integer_dtype(self.data.columns): C = self.data.columns[C] self.C = C From dd3910bc2bbc69e38c24dc284b2edca937f00dfc Mon Sep 17 00:00:00 2001 From: Thomas Lazarus Date: Thu, 16 Nov 2023 19:58:37 -0600 Subject: [PATCH 3/3] Adds warning --- pandas/plotting/_matplotlib/core.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index ab5f093652de3..7c52168c902a0 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1250,6 +1250,11 @@ def __init__(self, data, x, y, **kwargs) -> None: MPLPlot.__init__(self, data, **kwargs) if x is None or y is None: raise ValueError(self._kind + " requires an x and y column") + if self.data.columns._holds_integer(): + raise Warning( + """_holds_integer is deprecated and may be removed in a future version. + Please cast to a int dtype before plotting.""" + ) if is_integer(x) and not is_integer_dtype(self.data.columns): x = self.data.columns[x] if is_integer(y) and not is_integer_dtype(self.data.columns): @@ -1322,6 +1327,11 @@ def __init__( self.norm = norm super().__init__(data, x, y, **kwargs) + if self.data.columns._holds_integer(): + raise Warning( + """_holds_integer is deprecated and may be removed in a future version. + Please cast to a int dtype before plotting.""" + ) if is_integer(c) and not is_integer_dtype(self.data.columns): c = self.data.columns[c] self.c = c @@ -1438,6 +1448,11 @@ def _kind(self) -> Literal["hexbin"]: def __init__(self, data, x, y, C=None, *, colorbar: bool = True, **kwargs) -> None: super().__init__(data, x, y, **kwargs) + if self.data.columns._holds_integer(): + raise Warning( + """_holds_integer is deprecated and may be removed in a future version. + Please cast to a int dtype before plotting.""" + ) if is_integer(C) and not is_integer_dtype(self.data.columns): C = self.data.columns[C] self.C = C