Skip to content

Commit

Permalink
Merge branch 'main' into pandas-devGH-24537/parr-fillna-test
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Jan 15, 2023
2 parents 5f494f0 + d3f0e9a commit e80ae82
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 26 deletions.
4 changes: 3 additions & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,11 @@ Other API changes
Deprecations
~~~~~~~~~~~~
- 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`)
- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`)
- Deprecated :func:`pandas.io.sql.execute` (:issue:`50185`)
- :meth:`Index.is_boolean` has been deprecated. Use :func:`pandas.api.types.is_bool_dtype` instead (:issue:`50042`)
- :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`)
- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`)
- :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`)

.. ---------------------------------------------------------------------------
.. _whatsnew_200.prior_deprecations:
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pandas.core.dtypes.common import (
ensure_int64,
ensure_platform_int,
is_bool_dtype,
is_categorical_dtype,
is_datetime64_dtype,
is_dict_like,
Expand Down Expand Up @@ -600,7 +601,7 @@ def _from_inferred_categories(
cats = to_datetime(inferred_categories, errors="coerce")
elif is_timedelta64_dtype(dtype.categories):
cats = to_timedelta(inferred_categories, errors="coerce")
elif dtype.categories.is_boolean():
elif is_bool_dtype(dtype.categories):
if true_values is None:
true_values = ["True", "TRUE", "true"]

Expand Down
49 changes: 37 additions & 12 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,9 @@ def is_boolean(self) -> bool:
"""
Check if the Index only consists of booleans.
.. deprecated:: 2.0.0
Use `pandas.api.types.is_bool_dtype` instead.
Returns
-------
bool
Expand Down Expand Up @@ -2220,6 +2223,12 @@ def is_boolean(self) -> bool:
>>> idx.is_boolean()
False
"""
warnings.warn(
f"{type(self).__name__}.is_boolean is deprecated. "
"Use pandas.api.types.is_bool_type instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.inferred_type in ["boolean"]

@final
Expand All @@ -2237,7 +2246,7 @@ def is_integer(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_boolean : Check if the Index only consists of booleans (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
Expand Down Expand Up @@ -2285,7 +2294,7 @@ def is_floating(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_boolean : Check if the Index only consists of booleans (deprecated).
is_integer : Check if the Index only consists of integers (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
Expand All @@ -2311,8 +2320,8 @@ def is_floating(self) -> bool:
False
"""
warnings.warn(
f"{type(self).__name__}.is_floating is deprecated."
"Use pandas.api.types.is_float_dtype instead",
f"{type(self).__name__}.is_floating is deprecated. "
"Use pandas.api.types.is_float_dtype instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
Expand All @@ -2330,7 +2339,7 @@ def is_numeric(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_boolean : Check if the Index only consists of booleans (deprecated).
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_object : Check if the Index is of the object dtype.
Expand Down Expand Up @@ -2373,7 +2382,7 @@ def is_object(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_boolean : Check if the Index only consists of booleans (deprecated).
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
Expand Down Expand Up @@ -2414,7 +2423,7 @@ def is_categorical(self) -> bool:
See Also
--------
CategoricalIndex : Index for categorical data.
is_boolean : Check if the Index only consists of booleans.
is_boolean : Check if the Index only consists of booleans (deprecated).
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
Expand Down Expand Up @@ -2457,7 +2466,7 @@ def is_interval(self) -> bool:
See Also
--------
IntervalIndex : Index for Interval objects.
is_boolean : Check if the Index only consists of booleans.
is_boolean : Check if the Index only consists of booleans (deprecated).
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
Expand All @@ -2478,12 +2487,28 @@ def is_interval(self) -> bool:
return self.inferred_type in ["interval"]

@final
def holds_integer(self) -> bool:
def _holds_integer(self) -> bool:
"""
Whether the type is an integer type.
"""
return self.inferred_type in ["integer", "mixed-integer"]

@final
def holds_integer(self) -> bool:
"""
Whether the type is an integer type.
.. deprecated:: 2.0.0
Use `pandas.api.types.infer_dtype` instead
"""
warnings.warn(
f"{type(self).__name__}.holds_integer is deprecated. "
"Use pandas.api.types.infer_dtype instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._holds_integer()

@cache_readonly
def inferred_type(self) -> str_t:
"""
Expand Down Expand Up @@ -5528,7 +5553,7 @@ def _should_fallback_to_positional(self) -> bool:
"""
Should an integer key be treated as positional?
"""
return not self.holds_integer()
return not self._holds_integer()

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

if (other.is_boolean() and self.is_numeric()) or (
self.is_boolean() and other.is_numeric()
if (is_bool_dtype(other) and self.is_numeric()) or (
is_bool_dtype(self) and other.is_numeric()
):
# GH#16877 Treat boolean labels passed to a numeric index as not
# found. Without this fix False and True would be treated as 0 and 1
Expand Down
6 changes: 3 additions & 3 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,15 +940,15 @@ def __call__(self, *args, **kwargs):
f"{kind} requires either y column or 'subplots=True'"
)
if y is not None:
if is_integer(y) and not data.columns.holds_integer():
if is_integer(y) and not data.columns._holds_integer():
y = data.columns[y]
# converted to series actually. copy to not modify
data = data[y].copy()
data.index.name = y
elif isinstance(data, ABCDataFrame):
data_cols = data.columns
if x is not None:
if is_integer(x) and not data.columns.holds_integer():
if is_integer(x) and not data.columns._holds_integer():
x = data_cols[x]
elif not isinstance(data[x], ABCSeries):
raise ValueError("x must be a label or position")
Expand All @@ -957,7 +957,7 @@ def __call__(self, *args, **kwargs):
# check if we have y as int or list of ints
int_ylist = is_list_like(y) and all(is_integer(c) for c in y)
int_y_arg = is_integer(y) or int_ylist
if int_y_arg and not data.columns.holds_integer():
if int_y_arg and not data.columns._holds_integer():
y = data_cols[y]

label_kw = kwargs["label"] if "label" in kwargs else False
Expand Down
8 changes: 4 additions & 4 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,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.columns._holds_integer():
x = self.data.columns[x]
if is_integer(y) and not self.data.columns.holds_integer():
if is_integer(y) and not self.data.columns._holds_integer():
y = self.data.columns[y]

# Scatter plot allows to plot objects data
Expand Down Expand Up @@ -1196,7 +1196,7 @@ def __init__(self, data, x, y, s=None, c=None, **kwargs) -> None:
elif is_hashable(s) and s in data.columns:
s = data[s]
super().__init__(data, x, y, s=s, **kwargs)
if is_integer(c) and not self.data.columns.holds_integer():
if is_integer(c) and not self.data.columns._holds_integer():
c = self.data.columns[c]
self.c = c

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

def __init__(self, data, x, y, C=None, **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.columns._holds_integer():
C = self.data.columns[C]
self.C = C

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/base/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Any

from pandas import Index
from pandas.api.types import is_bool_dtype


def allow_na_ops(obj: Any) -> bool:
"""Whether to skip test cases including NaN"""
is_bool_index = isinstance(obj, Index) and obj.is_boolean()
is_bool_index = isinstance(obj, Index) and is_bool_dtype(obj)
return not is_bool_index and obj._can_hold_na
3 changes: 3 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ def test_groupby_extension_transform(self, data_for_grouping, request):
def test_groupby_extension_apply(
self, data_for_grouping, groupby_apply_op, request
):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
with tm.maybe_produces_warning(
PerformanceWarning,
pa_version_under7p0 and not pa.types.is_duration(pa_dtype),
Expand Down Expand Up @@ -770,6 +771,7 @@ def test_value_counts(self, all_data, dropna, request):
super().test_value_counts(all_data, dropna)

def test_value_counts_with_normalize(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
with tm.maybe_produces_warning(
PerformanceWarning,
pa_version_under7p0 and not pa.types.is_duration(pa_dtype),
Expand Down Expand Up @@ -869,6 +871,7 @@ def test_sort_values_missing(

@pytest.mark.parametrize("ascending", [True, False])
def test_sort_values_frame(self, data_for_sorting, ascending, request):
pa_dtype = data_for_sorting.dtype.pyarrow_dtype
with tm.maybe_produces_warning(
PerformanceWarning,
pa_version_under7p0 and not pa.types.is_duration(pa_dtype),
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,12 @@ def test_inv(self, simple_index):
with pytest.raises(TypeError, match=msg):
~Series(idx)

def test_is_boolean_is_deprecated(self, simple_index):
# GH50042
idx = simple_index
with tm.assert_produces_warning(FutureWarning):
idx.is_boolean()

def test_is_floating_is_deprecated(self, simple_index):
# GH50042
idx = simple_index
Expand All @@ -809,6 +815,13 @@ def test_is_integer_is_deprecated(self, simple_index):
with tm.assert_produces_warning(FutureWarning):
idx.is_integer()

def test_holds_integer_deprecated(self, simple_index):
# GH50243
idx = simple_index
msg = f"{type(idx).__name__}.holds_integer is deprecated. "
with tm.assert_produces_warning(FutureWarning, match=msg):
idx.holds_integer()


class NumericBase(Base):
"""
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/indexes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
import pandas._testing as tm
from pandas.api.types import (
is_bool_dtype,
is_datetime64tz_dtype,
is_signed_integer_dtype,
pandas_dtype,
Expand Down Expand Up @@ -271,7 +272,7 @@ def test_union_base(self, index):
def test_difference_base(self, sort, index):
first = index[2:]
second = index[:4]
if index.is_boolean():
if is_bool_dtype(index):
# i think (TODO: be sure) there assumptions baked in about
# the index fixture that don't hold here?
answer = set(first).difference(set(second))
Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
to_timedelta,
)
import pandas._testing as tm
from pandas.api.types import is_scalar
from pandas.api.types import (
is_bool_dtype,
is_scalar,
)
from pandas.core.api import Float64Index
from pandas.core.indexing import _one_ellipsis_message
from pandas.tests.indexing.common import check_indexing_smoketest_or_raises
Expand Down Expand Up @@ -1658,7 +1661,7 @@ def test_loc_iloc_getitem_leading_ellipses(self, series_with_simple_index, index
obj = series_with_simple_index
key = 0 if (indexer is tm.iloc or len(obj) == 0) else obj.index[0]

if indexer is tm.loc and obj.index.is_boolean():
if indexer is tm.loc and is_bool_dtype(obj.index):
# passing [False] will get interpreted as a boolean mask
# TODO: should it? unambiguous when lengths dont match?
return
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ disable = [

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

0 comments on commit e80ae82

Please sign in to comment.