Skip to content

Commit 01693d6

Browse files
bang128topper-123
andauthored
DEPR: deprecate Index.is_object (#50227)
* Deprecate is_object Co-authored-by: Terji Petersen <[email protected]>
1 parent 4ce3757 commit 01693d6

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ Deprecations
637637
- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`)
638638
- :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`)
639639
- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`)
640+
- :meth:`Index.is_object` has been deprecated. Use :func:`pandas.api.types.is_object_dtype` instead (:issue:`50042`)
640641
- :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`)
641642
-
642643

pandas/core/indexes/base.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ def _format_native_types(
13481348
return formatter.get_result_as_array()
13491349

13501350
mask = isna(self)
1351-
if not self.is_object() and not quoting:
1351+
if not is_object_dtype(self) and not quoting:
13521352
values = np.asarray(self).astype(str)
13531353
else:
13541354
values = np.array(self, dtype=object, copy=True)
@@ -2258,7 +2258,7 @@ def is_boolean(self) -> bool:
22582258
is_integer : Check if the Index only consists of integers (deprecated).
22592259
is_floating : Check if the Index is a floating type (deprecated).
22602260
is_numeric : Check if the Index only consists of numeric data.
2261-
is_object : Check if the Index is of the object dtype.
2261+
is_object : Check if the Index is of the object dtype (deprecated).
22622262
is_categorical : Check if the Index holds categorical data.
22632263
is_interval : Check if the Index holds Interval objects (deprecated).
22642264
@@ -2302,7 +2302,7 @@ def is_integer(self) -> bool:
23022302
is_boolean : Check if the Index only consists of booleans (deprecated).
23032303
is_floating : Check if the Index is a floating type (deprecated).
23042304
is_numeric : Check if the Index only consists of numeric data.
2305-
is_object : Check if the Index is of the object dtype.
2305+
is_object : Check if the Index is of the object dtype. (deprecated).
23062306
is_categorical : Check if the Index holds categorical data (deprecated).
23072307
is_interval : Check if the Index holds Interval objects (deprecated).
23082308
@@ -2350,7 +2350,7 @@ def is_floating(self) -> bool:
23502350
is_boolean : Check if the Index only consists of booleans (deprecated).
23512351
is_integer : Check if the Index only consists of integers (deprecated).
23522352
is_numeric : Check if the Index only consists of numeric data.
2353-
is_object : Check if the Index is of the object dtype.
2353+
is_object : Check if the Index is of the object dtype. (deprecated).
23542354
is_categorical : Check if the Index holds categorical data (deprecated).
23552355
is_interval : Check if the Index holds Interval objects (deprecated).
23562356
@@ -2395,7 +2395,7 @@ def is_numeric(self) -> bool:
23952395
is_boolean : Check if the Index only consists of booleans (deprecated).
23962396
is_integer : Check if the Index only consists of integers (deprecated).
23972397
is_floating : Check if the Index is a floating type (deprecated).
2398-
is_object : Check if the Index is of the object dtype.
2398+
is_object : Check if the Index is of the object dtype. (deprecated).
23992399
is_categorical : Check if the Index holds categorical data (deprecated).
24002400
is_interval : Check if the Index holds Interval objects (deprecated).
24012401
@@ -2428,6 +2428,9 @@ def is_object(self) -> bool:
24282428
"""
24292429
Check if the Index is of the object dtype.
24302430
2431+
.. deprecated:: 2.0.0
2432+
Use `pandas.api.types.is_object_dtype` instead.
2433+
24312434
Returns
24322435
-------
24332436
bool
@@ -2461,6 +2464,12 @@ def is_object(self) -> bool:
24612464
>>> idx.is_object()
24622465
False
24632466
"""
2467+
warnings.warn(
2468+
f"{type(self).__name__}.is_object is deprecated."
2469+
"Use pandas.api.types.is_object_dtype instead",
2470+
FutureWarning,
2471+
stacklevel=find_stack_level(),
2472+
)
24642473
return is_object_dtype(self.dtype)
24652474

24662475
@final
@@ -2483,7 +2492,7 @@ def is_categorical(self) -> bool:
24832492
is_integer : Check if the Index only consists of integers (deprecated).
24842493
is_floating : Check if the Index is a floating type (deprecated).
24852494
is_numeric : Check if the Index only consists of numeric data.
2486-
is_object : Check if the Index is of the object dtype.
2495+
is_object : Check if the Index is of the object dtype. (deprecated).
24872496
is_interval : Check if the Index holds Interval objects (deprecated).
24882497
24892498
Examples
@@ -2536,7 +2545,7 @@ def is_interval(self) -> bool:
25362545
is_integer : Check if the Index only consists of integers (deprecated).
25372546
is_floating : Check if the Index is a floating type (deprecated).
25382547
is_numeric : Check if the Index only consists of numeric data.
2539-
is_object : Check if the Index is of the object dtype.
2548+
is_object : Check if the Index is of the object dtype. (deprecated).
25402549
is_categorical : Check if the Index holds categorical data (deprecated).
25412550
25422551
Examples
@@ -5018,7 +5027,7 @@ def _is_memory_usage_qualified(self) -> bool:
50185027
"""
50195028
Return a boolean if we need a qualified .info display.
50205029
"""
5021-
return self.is_object()
5030+
return is_object_dtype(self.dtype)
50225031

50235032
def __contains__(self, key: Any) -> bool:
50245033
"""
@@ -5132,7 +5141,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool:
51325141
https://github.com/pandas-dev/pandas/issues/19764
51335142
"""
51345143
if (
5135-
self.is_object()
5144+
is_object_dtype(self.dtype)
51365145
or is_string_dtype(self.dtype)
51375146
or is_categorical_dtype(self.dtype)
51385147
):

pandas/io/pytables.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
is_extension_array_dtype,
7373
is_integer_dtype,
7474
is_list_like,
75+
is_object_dtype,
7576
is_string_dtype,
7677
is_timedelta64_dtype,
7778
needs_i8_conversion,
@@ -2560,7 +2561,7 @@ class DataIndexableCol(DataCol):
25602561
is_data_indexable = True
25612562

25622563
def validate_names(self) -> None:
2563-
if not Index(self.values).is_object():
2564+
if not is_object_dtype(Index(self.values)):
25642565
# TODO: should the message here be more specifically non-str?
25652566
raise ValueError("cannot have non-object label DataIndexableCol")
25662567

pandas/tests/indexes/common.py

+6
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ def test_is_interval_is_deprecated(self, simple_index):
829829
with tm.assert_produces_warning(FutureWarning):
830830
idx.is_interval()
831831

832+
def test_is_object_is_deprecated(self, simple_index):
833+
# GH50042
834+
idx = simple_index
835+
with tm.assert_produces_warning(FutureWarning):
836+
idx.is_object()
837+
832838

833839
class NumericBase(Base):
834840
"""

pandas/tests/indexes/test_base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
)
1919
from pandas.util._test_decorators import async_mark
2020

21-
from pandas.core.dtypes.common import is_numeric_dtype
21+
from pandas.core.dtypes.common import (
22+
is_numeric_dtype,
23+
is_object_dtype,
24+
)
2225

2326
import pandas as pd
2427
from pandas import (
@@ -677,7 +680,7 @@ def test_is_numeric(self, index, expected):
677680
indirect=["index"],
678681
)
679682
def test_is_object(self, index, expected):
680-
assert index.is_object() is expected
683+
assert is_object_dtype(index) is expected
681684

682685
def test_summary(self, index):
683686
index._summary()

pandas/tests/indexing/test_indexing.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pandas.core.dtypes.common import (
1414
is_float_dtype,
1515
is_integer_dtype,
16+
is_object_dtype,
1617
)
1718

1819
import pandas as pd
@@ -618,7 +619,7 @@ def test_index_type_coercion(self, indexer):
618619

619620
s2 = s.copy()
620621
indexer(s2)["0"] = 0
621-
assert s2.index.is_object()
622+
assert is_object_dtype(s2.index)
622623

623624
for s in [Series(range(5), index=np.arange(5.0))]:
624625

@@ -635,7 +636,7 @@ def test_index_type_coercion(self, indexer):
635636

636637
s2 = s.copy()
637638
indexer(s2)["0"] = 0
638-
assert s2.index.is_object()
639+
assert is_object_dtype(s2.index)
639640

640641

641642
class TestMisc:

pandas/tests/series/methods/test_drop.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Series,
66
)
77
import pandas._testing as tm
8+
from pandas.api.types import is_bool_dtype
89

910

1011
@pytest.mark.parametrize(
@@ -57,7 +58,7 @@ def test_drop_with_ignore_errors():
5758

5859
# GH 8522
5960
ser = Series([2, 3], index=[True, False])
60-
assert not ser.index.is_object()
61+
assert is_bool_dtype(ser.index)
6162
assert ser.index.dtype == bool
6263
result = ser.drop(True)
6364
expected = Series([3], index=[False])

0 commit comments

Comments
 (0)