Skip to content

Commit e80ae82

Browse files
authored
Merge branch 'main' into pandas-devGH-24537/parr-fillna-test
2 parents 5f494f0 + d3f0e9a commit e80ae82

File tree

11 files changed

+75
-26
lines changed

11 files changed

+75
-26
lines changed

doc/source/whatsnew/v2.0.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,11 @@ Other API changes
572572
Deprecations
573573
~~~~~~~~~~~~
574574
- Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`)
575-
- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`)
575+
- Deprecated :func:`pandas.io.sql.execute` (:issue:`50185`)
576+
- :meth:`Index.is_boolean` has been deprecated. Use :func:`pandas.api.types.is_bool_dtype` instead (:issue:`50042`)
576577
- :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`)
577578
- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`)
579+
- :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`)
578580

579581
.. ---------------------------------------------------------------------------
580582
.. _whatsnew_200.prior_deprecations:

pandas/core/arrays/categorical.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from pandas.core.dtypes.common import (
4848
ensure_int64,
4949
ensure_platform_int,
50+
is_bool_dtype,
5051
is_categorical_dtype,
5152
is_datetime64_dtype,
5253
is_dict_like,
@@ -600,7 +601,7 @@ def _from_inferred_categories(
600601
cats = to_datetime(inferred_categories, errors="coerce")
601602
elif is_timedelta64_dtype(dtype.categories):
602603
cats = to_timedelta(inferred_categories, errors="coerce")
603-
elif dtype.categories.is_boolean():
604+
elif is_bool_dtype(dtype.categories):
604605
if true_values is None:
605606
true_values = ["True", "TRUE", "true"]
606607

pandas/core/indexes/base.py

+37-12
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,9 @@ def is_boolean(self) -> bool:
21922192
"""
21932193
Check if the Index only consists of booleans.
21942194
2195+
.. deprecated:: 2.0.0
2196+
Use `pandas.api.types.is_bool_dtype` instead.
2197+
21952198
Returns
21962199
-------
21972200
bool
@@ -2220,6 +2223,12 @@ def is_boolean(self) -> bool:
22202223
>>> idx.is_boolean()
22212224
False
22222225
"""
2226+
warnings.warn(
2227+
f"{type(self).__name__}.is_boolean is deprecated. "
2228+
"Use pandas.api.types.is_bool_type instead.",
2229+
FutureWarning,
2230+
stacklevel=find_stack_level(),
2231+
)
22232232
return self.inferred_type in ["boolean"]
22242233

22252234
@final
@@ -2237,7 +2246,7 @@ def is_integer(self) -> bool:
22372246
22382247
See Also
22392248
--------
2240-
is_boolean : Check if the Index only consists of booleans.
2249+
is_boolean : Check if the Index only consists of booleans (deprecated).
22412250
is_floating : Check if the Index is a floating type (deprecated).
22422251
is_numeric : Check if the Index only consists of numeric data.
22432252
is_object : Check if the Index is of the object dtype.
@@ -2285,7 +2294,7 @@ def is_floating(self) -> bool:
22852294
22862295
See Also
22872296
--------
2288-
is_boolean : Check if the Index only consists of booleans.
2297+
is_boolean : Check if the Index only consists of booleans (deprecated).
22892298
is_integer : Check if the Index only consists of integers (deprecated).
22902299
is_numeric : Check if the Index only consists of numeric data.
22912300
is_object : Check if the Index is of the object dtype.
@@ -2311,8 +2320,8 @@ def is_floating(self) -> bool:
23112320
False
23122321
"""
23132322
warnings.warn(
2314-
f"{type(self).__name__}.is_floating is deprecated."
2315-
"Use pandas.api.types.is_float_dtype instead",
2323+
f"{type(self).__name__}.is_floating is deprecated. "
2324+
"Use pandas.api.types.is_float_dtype instead.",
23162325
FutureWarning,
23172326
stacklevel=find_stack_level(),
23182327
)
@@ -2330,7 +2339,7 @@ def is_numeric(self) -> bool:
23302339
23312340
See Also
23322341
--------
2333-
is_boolean : Check if the Index only consists of booleans.
2342+
is_boolean : Check if the Index only consists of booleans (deprecated).
23342343
is_integer : Check if the Index only consists of integers (deprecated).
23352344
is_floating : Check if the Index is a floating type (deprecated).
23362345
is_object : Check if the Index is of the object dtype.
@@ -2373,7 +2382,7 @@ def is_object(self) -> bool:
23732382
23742383
See Also
23752384
--------
2376-
is_boolean : Check if the Index only consists of booleans.
2385+
is_boolean : Check if the Index only consists of booleans (deprecated).
23772386
is_integer : Check if the Index only consists of integers (deprecated).
23782387
is_floating : Check if the Index is a floating type (deprecated).
23792388
is_numeric : Check if the Index only consists of numeric data.
@@ -2414,7 +2423,7 @@ def is_categorical(self) -> bool:
24142423
See Also
24152424
--------
24162425
CategoricalIndex : Index for categorical data.
2417-
is_boolean : Check if the Index only consists of booleans.
2426+
is_boolean : Check if the Index only consists of booleans (deprecated).
24182427
is_integer : Check if the Index only consists of integers (deprecated).
24192428
is_floating : Check if the Index is a floating type (deprecated).
24202429
is_numeric : Check if the Index only consists of numeric data.
@@ -2457,7 +2466,7 @@ def is_interval(self) -> bool:
24572466
See Also
24582467
--------
24592468
IntervalIndex : Index for Interval objects.
2460-
is_boolean : Check if the Index only consists of booleans.
2469+
is_boolean : Check if the Index only consists of booleans (deprecated).
24612470
is_integer : Check if the Index only consists of integers (deprecated).
24622471
is_floating : Check if the Index is a floating type (deprecated).
24632472
is_numeric : Check if the Index only consists of numeric data.
@@ -2478,12 +2487,28 @@ def is_interval(self) -> bool:
24782487
return self.inferred_type in ["interval"]
24792488

24802489
@final
2481-
def holds_integer(self) -> bool:
2490+
def _holds_integer(self) -> bool:
24822491
"""
24832492
Whether the type is an integer type.
24842493
"""
24852494
return self.inferred_type in ["integer", "mixed-integer"]
24862495

2496+
@final
2497+
def holds_integer(self) -> bool:
2498+
"""
2499+
Whether the type is an integer type.
2500+
2501+
.. deprecated:: 2.0.0
2502+
Use `pandas.api.types.infer_dtype` instead
2503+
"""
2504+
warnings.warn(
2505+
f"{type(self).__name__}.holds_integer is deprecated. "
2506+
"Use pandas.api.types.infer_dtype instead.",
2507+
FutureWarning,
2508+
stacklevel=find_stack_level(),
2509+
)
2510+
return self._holds_integer()
2511+
24872512
@cache_readonly
24882513
def inferred_type(self) -> str_t:
24892514
"""
@@ -5528,7 +5553,7 @@ def _should_fallback_to_positional(self) -> bool:
55285553
"""
55295554
Should an integer key be treated as positional?
55305555
"""
5531-
return not self.holds_integer()
5556+
return not self._holds_integer()
55325557

55335558
_index_shared_docs[
55345559
"get_indexer_non_unique"
@@ -5874,8 +5899,8 @@ def _should_compare(self, other: Index) -> bool:
58745899
Check if `self == other` can ever have non-False entries.
58755900
"""
58765901

5877-
if (other.is_boolean() and self.is_numeric()) or (
5878-
self.is_boolean() and other.is_numeric()
5902+
if (is_bool_dtype(other) and self.is_numeric()) or (
5903+
is_bool_dtype(self) and other.is_numeric()
58795904
):
58805905
# GH#16877 Treat boolean labels passed to a numeric index as not
58815906
# found. Without this fix False and True would be treated as 0 and 1

pandas/plotting/_core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -940,15 +940,15 @@ def __call__(self, *args, **kwargs):
940940
f"{kind} requires either y column or 'subplots=True'"
941941
)
942942
if y is not None:
943-
if is_integer(y) and not data.columns.holds_integer():
943+
if is_integer(y) and not data.columns._holds_integer():
944944
y = data.columns[y]
945945
# converted to series actually. copy to not modify
946946
data = data[y].copy()
947947
data.index.name = y
948948
elif isinstance(data, ABCDataFrame):
949949
data_cols = data.columns
950950
if x is not None:
951-
if is_integer(x) and not data.columns.holds_integer():
951+
if is_integer(x) and not data.columns._holds_integer():
952952
x = data_cols[x]
953953
elif not isinstance(data[x], ABCSeries):
954954
raise ValueError("x must be a label or position")
@@ -957,7 +957,7 @@ def __call__(self, *args, **kwargs):
957957
# check if we have y as int or list of ints
958958
int_ylist = is_list_like(y) and all(is_integer(c) for c in y)
959959
int_y_arg = is_integer(y) or int_ylist
960-
if int_y_arg and not data.columns.holds_integer():
960+
if int_y_arg and not data.columns._holds_integer():
961961
y = data_cols[y]
962962

963963
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
@@ -1137,9 +1137,9 @@ def __init__(self, data, x, y, **kwargs) -> None:
11371137
MPLPlot.__init__(self, data, **kwargs)
11381138
if x is None or y is None:
11391139
raise ValueError(self._kind + " requires an x and y column")
1140-
if is_integer(x) and not self.data.columns.holds_integer():
1140+
if is_integer(x) and not self.data.columns._holds_integer():
11411141
x = self.data.columns[x]
1142-
if is_integer(y) and not self.data.columns.holds_integer():
1142+
if is_integer(y) and not self.data.columns._holds_integer():
11431143
y = self.data.columns[y]
11441144

11451145
# Scatter plot allows to plot objects data
@@ -1196,7 +1196,7 @@ def __init__(self, data, x, y, s=None, c=None, **kwargs) -> None:
11961196
elif is_hashable(s) and s in data.columns:
11971197
s = data[s]
11981198
super().__init__(data, x, y, s=s, **kwargs)
1199-
if is_integer(c) and not self.data.columns.holds_integer():
1199+
if is_integer(c) and not self.data.columns._holds_integer():
12001200
c = self.data.columns[c]
12011201
self.c = c
12021202

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

12921292
def __init__(self, data, x, y, C=None, **kwargs) -> None:
12931293
super().__init__(data, x, y, **kwargs)
1294-
if is_integer(C) and not self.data.columns.holds_integer():
1294+
if is_integer(C) and not self.data.columns._holds_integer():
12951295
C = self.data.columns[C]
12961296
self.C = C
12971297

pandas/tests/base/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from typing import Any
22

33
from pandas import Index
4+
from pandas.api.types import is_bool_dtype
45

56

67
def allow_na_ops(obj: Any) -> bool:
78
"""Whether to skip test cases including NaN"""
8-
is_bool_index = isinstance(obj, Index) and obj.is_boolean()
9+
is_bool_index = isinstance(obj, Index) and is_bool_dtype(obj)
910
return not is_bool_index and obj._can_hold_na

pandas/tests/extension/test_arrow.py

+3
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ def test_groupby_extension_transform(self, data_for_grouping, request):
528528
def test_groupby_extension_apply(
529529
self, data_for_grouping, groupby_apply_op, request
530530
):
531+
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
531532
with tm.maybe_produces_warning(
532533
PerformanceWarning,
533534
pa_version_under7p0 and not pa.types.is_duration(pa_dtype),
@@ -770,6 +771,7 @@ def test_value_counts(self, all_data, dropna, request):
770771
super().test_value_counts(all_data, dropna)
771772

772773
def test_value_counts_with_normalize(self, data, request):
774+
pa_dtype = data.dtype.pyarrow_dtype
773775
with tm.maybe_produces_warning(
774776
PerformanceWarning,
775777
pa_version_under7p0 and not pa.types.is_duration(pa_dtype),
@@ -869,6 +871,7 @@ def test_sort_values_missing(
869871

870872
@pytest.mark.parametrize("ascending", [True, False])
871873
def test_sort_values_frame(self, data_for_sorting, ascending, request):
874+
pa_dtype = data_for_sorting.dtype.pyarrow_dtype
872875
with tm.maybe_produces_warning(
873876
PerformanceWarning,
874877
pa_version_under7p0 and not pa.types.is_duration(pa_dtype),

pandas/tests/indexes/common.py

+13
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,12 @@ def test_inv(self, simple_index):
797797
with pytest.raises(TypeError, match=msg):
798798
~Series(idx)
799799

800+
def test_is_boolean_is_deprecated(self, simple_index):
801+
# GH50042
802+
idx = simple_index
803+
with tm.assert_produces_warning(FutureWarning):
804+
idx.is_boolean()
805+
800806
def test_is_floating_is_deprecated(self, simple_index):
801807
# GH50042
802808
idx = simple_index
@@ -809,6 +815,13 @@ def test_is_integer_is_deprecated(self, simple_index):
809815
with tm.assert_produces_warning(FutureWarning):
810816
idx.is_integer()
811817

818+
def test_holds_integer_deprecated(self, simple_index):
819+
# GH50243
820+
idx = simple_index
821+
msg = f"{type(idx).__name__}.holds_integer is deprecated. "
822+
with tm.assert_produces_warning(FutureWarning, match=msg):
823+
idx.holds_integer()
824+
812825

813826
class NumericBase(Base):
814827
"""

pandas/tests/indexes/test_setops.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
import pandas._testing as tm
2727
from pandas.api.types import (
28+
is_bool_dtype,
2829
is_datetime64tz_dtype,
2930
is_signed_integer_dtype,
3031
pandas_dtype,
@@ -271,7 +272,7 @@ def test_union_base(self, index):
271272
def test_difference_base(self, sort, index):
272273
first = index[2:]
273274
second = index[:4]
274-
if index.is_boolean():
275+
if is_bool_dtype(index):
275276
# i think (TODO: be sure) there assumptions baked in about
276277
# the index fixture that don't hold here?
277278
answer = set(first).difference(set(second))

pandas/tests/indexing/test_loc.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
to_timedelta,
3838
)
3939
import pandas._testing as tm
40-
from pandas.api.types import is_scalar
40+
from pandas.api.types import (
41+
is_bool_dtype,
42+
is_scalar,
43+
)
4144
from pandas.core.api import Float64Index
4245
from pandas.core.indexing import _one_ellipsis_message
4346
from pandas.tests.indexing.common import check_indexing_smoketest_or_raises
@@ -1658,7 +1661,7 @@ def test_loc_iloc_getitem_leading_ellipses(self, series_with_simple_index, index
16581661
obj = series_with_simple_index
16591662
key = 0 if (indexer is tm.iloc or len(obj) == 0) else obj.index[0]
16601663

1661-
if indexer is tm.loc and obj.index.is_boolean():
1664+
if indexer is tm.loc and is_bool_dtype(obj.index):
16621665
# passing [False] will get interpreted as a boolean mask
16631666
# TODO: should it? unambiguous when lengths dont match?
16641667
return

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ disable = [
356356

357357
[tool.pytest.ini_options]
358358
# sync minversion with pyproject.toml & install.rst
359-
minversion = "6.0"
359+
minversion = "7.0"
360360
addopts = "--strict-data-files --strict-markers --strict-config --capture=no --durations=30 --junitxml=test-data.xml"
361361
empty_parameter_set_mark = "fail_at_collect"
362362
xfail_strict = true

0 commit comments

Comments
 (0)