Skip to content

Commit

Permalink
silence infer_objects warning for object backed string type
Browse files Browse the repository at this point in the history
  • Loading branch information
lithomas1 committed Sep 9, 2024
1 parent 3c4bc03 commit 01b5d26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,12 @@ def __init__(

NDFrame.__init__(self, mgr)

if original_dtype is None and is_pandas_object and data_dtype == np.object_:
if (
original_dtype is None
and is_pandas_object
and data_dtype == np.object_
and self.dtypes.iloc[0] != "str"
):
if self.dtypes.iloc[0] != data_dtype:
warnings.warn(
"Dtype inference on a pandas object "
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,13 @@ def __new__(

arr = klass._ensure_array(arr, arr.dtype, copy=False)
result = klass._simple_new(arr, name, refs=refs)
if dtype is None and is_pandas_object and data_dtype == np.object_:
# TODO: also verify this check
if (
dtype is None
and is_pandas_object
and data_dtype == np.object_
and result.dtype != "str"
):
if result.dtype != data_dtype:
warnings.warn(
"Dtype inference on a pandas object "
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,13 @@ def __init__(
self.name = name
self._set_axis(0, index)

if original_dtype is None and is_pandas_object and data_dtype == np.object_:
# TODO: verify we're silencing the warning correctly here
if (
original_dtype is None
and is_pandas_object
and data_dtype == np.object_
and self.dtype != "str"
):
if self.dtype != data_dtype:
warnings.warn(
"Dtype inference on a pandas object "
Expand Down

0 comments on commit 01b5d26

Please sign in to comment.