-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEPR: Deprecate dtype inference on pandas objects #56244
Changes from 14 commits
86700a7
7daf535
2b28aa2
d55dfc8
329edb3
1c6c3e3
855340b
5a6244c
24eff80
eef58ea
ab2a735
ab62a31
0e828b7
86f1a94
cd067cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -726,6 +726,10 @@ def __init__( | |
|
||
manager = _get_option("mode.data_manager", silent=True) | ||
|
||
is_pandas_object = isinstance(data, (Series, Index, ExtensionArray)) | ||
data_dtype = getattr(data, "dtype", None) | ||
original_dtype = dtype | ||
|
||
# GH47215 | ||
if isinstance(index, set): | ||
raise ValueError("index cannot be a set") | ||
|
@@ -912,6 +916,18 @@ def __init__( | |
|
||
NDFrame.__init__(self, mgr) | ||
|
||
if original_dtype is None and is_pandas_object and data_dtype == np.object_: | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if self.dtypes.iloc[0] != data_dtype: | ||
warnings.warn( | ||
"Dtype inference on a pandas object " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "in the DataFrame constructor" somewhere in this sentence? I think the "The Index constructor" below is a copy/paste leftover There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah sorry, adjusted |
||
"(Series, Index, ExtensionArray) is deprecated. The DataFrame " | ||
"constructor will keep the original dtype in the future. " | ||
"Call `infer_objects` on the result to get the old " | ||
"behavior.", | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
|
||
# ---------------------------------------------------------------------- | ||
|
||
def __dataframe__( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,9 +259,10 @@ def test_dt_accessor_limited_display_api(self): | |
tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods))) | ||
|
||
# Period | ||
ser = Series( | ||
period_range("20130101", periods=5, freq="D", name="xxx").astype(object) | ||
) | ||
with tm.assert_produces_warning(FutureWarning, match="Dtype inference"): | ||
ser = Series( | ||
period_range("20130101", periods=5, freq="D", name="xxx").astype(object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you construct the index outside the context so it is obvious where the warning comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved |
||
) | ||
results = get_dir(ser) | ||
tm.assert_almost_equal( | ||
results, sorted(set(ok_for_period + ok_for_period_methods)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ def test_between(self): | |
tm.assert_series_equal(result, expected) | ||
|
||
def test_between_datetime_object_dtype(self): | ||
ser = Series(bdate_range("1/1/2000", periods=20).astype(object)) | ||
ser = Series(bdate_range("1/1/2000", periods=20).astype(object), dtype=object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The .astype(object) here is redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yes, changed |
||
ser[::2] = np.nan | ||
|
||
result = ser[ser.between(ser[3], ser[17])] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the input -> on the result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either way is totally fine