Skip to content

Updates to check the dtypes instead #55965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
12 changes: 7 additions & 5 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this we'd want to use is_integer_dtype. we'd also need to check for object dtype that _holds_integer and issue a warning that it is deprecated and the user should cast (similar above)

C = self.data.columns[C]
self.C = C

Expand Down