Skip to content

Commit c60ac19

Browse files
Terji PetersenTerji Petersen
Terji Petersen
authored and
Terji Petersen
committed
use ._should_fallback_to_positional
1 parent c810830 commit c60ac19

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

pandas/plotting/_core.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from pandas.core.dtypes.common import (
1919
is_integer,
20-
is_integer_dtype,
2120
is_list_like,
2221
)
2322
from pandas.core.dtypes.generic import (
@@ -940,15 +939,15 @@ def __call__(self, *args, **kwargs):
940939
f"{kind} requires either y column or 'subplots=True'"
941940
)
942941
if y is not None:
943-
if is_integer(y) and not is_integer_dtype(data.columns):
942+
if is_integer(y) and data.columns._should_fallback_to_positional:
944943
y = data.columns[y]
945944
# converted to series actually. copy to not modify
946945
data = data[y].copy()
947946
data.index.name = y
948947
elif isinstance(data, ABCDataFrame):
949948
data_cols = data.columns
950949
if x is not None:
951-
if is_integer(x) and not is_integer_dtype(data.columns):
950+
if is_integer(x) and data.columns._should_fallback_to_positional:
952951
x = data_cols[x]
953952
elif not isinstance(data[x], ABCSeries):
954953
raise ValueError("x must be a label or position")
@@ -957,7 +956,7 @@ def __call__(self, *args, **kwargs):
957956
# check if we have y as int or list of ints
958957
int_ylist = is_list_like(y) and all(is_integer(c) for c in y)
959958
int_y_arg = is_integer(y) or int_ylist
960-
if int_y_arg and not is_integer_dtype(data.columns):
959+
if int_y_arg and data.columns._should_fallback_to_positional:
961960
y = data_cols[y]
962961

963962
label_kw = kwargs["label"] if "label" in kwargs else False

pandas/plotting/_matplotlib/core.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,9 @@ def __init__(self, data, x, y, **kwargs) -> None:
11351135
MPLPlot.__init__(self, data, **kwargs)
11361136
if x is None or y is None:
11371137
raise ValueError(self._kind + " requires an x and y column")
1138-
if is_integer(x) and not is_integer_dtype(self.data.columns):
1138+
if is_integer(x) and self.data.columns._should_fallback_to_positional:
11391139
x = self.data.columns[x]
1140-
if is_integer(y) and not is_integer_dtype(self.data.columns):
1140+
if is_integer(y) and self.data.columns._should_fallback_to_positional:
11411141
y = self.data.columns[y]
11421142

11431143
# Scatter plot allows to plot objects data
@@ -1194,7 +1194,7 @@ def __init__(self, data, x, y, s=None, c=None, **kwargs) -> None:
11941194
elif is_hashable(s) and s in data.columns:
11951195
s = data[s]
11961196
super().__init__(data, x, y, s=s, **kwargs)
1197-
if is_integer(c) and not is_integer_dtype(self.data.columns):
1197+
if is_integer(c) and self.data.columns._should_fallback_to_positional:
11981198
c = self.data.columns[c]
11991199
self.c = c
12001200

@@ -1286,7 +1286,7 @@ def _kind(self) -> Literal["hexbin"]:
12861286

12871287
def __init__(self, data, x, y, C=None, **kwargs) -> None:
12881288
super().__init__(data, x, y, **kwargs)
1289-
if is_integer(C) and not is_integer_dtype(self.data.columns):
1289+
if is_integer(C) and self.data.columns._should_fallback_to_positional:
12901290
C = self.data.columns[C]
12911291
self.C = C
12921292

0 commit comments

Comments
 (0)