Skip to content

Commit 01b5d26

Browse files
committed
silence infer_objects warning for object backed string type
1 parent 3c4bc03 commit 01b5d26

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

pandas/core/frame.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,12 @@ def __init__(
923923

924924
NDFrame.__init__(self, mgr)
925925

926-
if original_dtype is None and is_pandas_object and data_dtype == np.object_:
926+
if (
927+
original_dtype is None
928+
and is_pandas_object
929+
and data_dtype == np.object_
930+
and self.dtypes.iloc[0] != "str"
931+
):
927932
if self.dtypes.iloc[0] != data_dtype:
928933
warnings.warn(
929934
"Dtype inference on a pandas object "

pandas/core/indexes/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,13 @@ def __new__(
575575

576576
arr = klass._ensure_array(arr, arr.dtype, copy=False)
577577
result = klass._simple_new(arr, name, refs=refs)
578-
if dtype is None and is_pandas_object and data_dtype == np.object_:
578+
# TODO: also verify this check
579+
if (
580+
dtype is None
581+
and is_pandas_object
582+
and data_dtype == np.object_
583+
and result.dtype != "str"
584+
):
579585
if result.dtype != data_dtype:
580586
warnings.warn(
581587
"Dtype inference on a pandas object "

pandas/core/series.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,13 @@ def __init__(
593593
self.name = name
594594
self._set_axis(0, index)
595595

596-
if original_dtype is None and is_pandas_object and data_dtype == np.object_:
596+
# TODO: verify we're silencing the warning correctly here
597+
if (
598+
original_dtype is None
599+
and is_pandas_object
600+
and data_dtype == np.object_
601+
and self.dtype != "str"
602+
):
597603
if self.dtype != data_dtype:
598604
warnings.warn(
599605
"Dtype inference on a pandas object "

0 commit comments

Comments
 (0)