Skip to content

Commit eb72fa4

Browse files
bang128topper-123
authored andcommitted
Deprecate is_object
1 parent ee03ed1 commit eb72fa4

File tree

7 files changed

+16063
-10
lines changed

7 files changed

+16063
-10
lines changed

data.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
,,,1,2
2+
x,y,z,,
3+
1,3,5,,
4+
2,4,6,,

data.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"{\"schema\":{\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"a\",\"type\":\"number\"},{\"name\":\"b\",\"type\":\"number\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"1.4.0\"},\"data\":[{\"index\":0,\"a\":{\"imag\":2.0,\"real\":1.0},\"b\":{\"imag\":6.0,\"real\":5.0}},{\"index\":1,\"a\":{\"imag\":4.0,\"real\":3.0},\"b\":{\"imag\":8.0,\"real\":7.0}}]}"

doc/source/user_guide/style.nbconvert.ipynb

+16,030
Large diffs are not rendered by default.

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-8
Original file line numberDiff line numberDiff line change
@@ -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
@@ -2427,6 +2427,8 @@ def is_numeric(self) -> bool:
24272427
def is_object(self) -> bool:
24282428
"""
24292429
Check if the Index is of the object dtype.
2430+
.. deprecated:: 2.0.0
2431+
Use `pandas.api.types.is_object_dtype` instead.
24302432
24312433
Returns
24322434
-------
@@ -2461,6 +2463,14 @@ def is_object(self) -> bool:
24612463
>>> idx.is_object()
24622464
False
24632465
"""
2466+
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+
)
2473+
24642474
return is_object_dtype(self.dtype)
24652475

24662476
@final
@@ -2483,7 +2493,7 @@ def is_categorical(self) -> bool:
24832493
is_integer : Check if the Index only consists of integers (deprecated).
24842494
is_floating : Check if the Index is a floating type (deprecated).
24852495
is_numeric : Check if the Index only consists of numeric data.
2486-
is_object : Check if the Index is of the object dtype.
2496+
is_object : Check if the Index is of the object dtype. (deprecated)
24872497
is_interval : Check if the Index holds Interval objects (deprecated).
24882498
24892499
Examples
@@ -2536,7 +2546,7 @@ def is_interval(self) -> bool:
25362546
is_integer : Check if the Index only consists of integers (deprecated).
25372547
is_floating : Check if the Index is a floating type (deprecated).
25382548
is_numeric : Check if the Index only consists of numeric data.
2539-
is_object : Check if the Index is of the object dtype.
2549+
is_object : Check if the Index is of the object dtype. (deprecated)
25402550
is_categorical : Check if the Index holds categorical data (deprecated).
25412551
25422552
Examples
@@ -5018,7 +5028,7 @@ def _is_memory_usage_qualified(self) -> bool:
50185028
"""
50195029
Return a boolean if we need a qualified .info display.
50205030
"""
5021-
return self.is_object()
5031+
return is_object_dtype(self.dtype)
50225032

50235033
def __contains__(self, key: Any) -> bool:
50245034
"""
@@ -5132,7 +5142,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool:
51325142
https://github.com/pandas-dev/pandas/issues/19764
51335143
"""
51345144
if (
5135-
self.is_object()
5145+
is_object_dtype(self.dtype)
51365146
or is_string_dtype(self.dtype)
51375147
or is_categorical_dtype(self.dtype)
51385148
):

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/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:

0 commit comments

Comments
 (0)