Skip to content

REF: remove NDFrame._convert #50026

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

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6315,37 +6315,6 @@ def __deepcopy__(self: NDFrameT, memo=None) -> NDFrameT:
"""
return self.copy(deep=True)

@final
def _convert(
self: NDFrameT,
*,
datetime: bool_t = False,
timedelta: bool_t = False,
) -> NDFrameT:
"""
Attempt to infer better dtype for object columns.

Parameters
----------
datetime : bool, default False
If True, convert to date where possible.
timedelta : bool, default False
If True, convert to timedelta where possible.

Returns
-------
converted : same as input object
"""
validate_bool_kwarg(datetime, "datetime")
validate_bool_kwarg(timedelta, "timedelta")
return self._constructor(
self._mgr.convert(
datetime=datetime,
timedelta=timedelta,
copy=True,
)
).__finalize__(self)

@final
def infer_objects(self: NDFrameT) -> NDFrameT:
"""
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,9 +1681,8 @@ def _wrap_agged_manager(self, mgr: Manager2D) -> DataFrame:
if self.axis == 1:
result = result.T

# Note: we only need to pass datetime=True in order to get numeric
# values converted
return self._reindex_output(result)._convert(datetime=True)
# Note: we really only care about inferring numeric dtypes here
return self._reindex_output(result).infer_objects()

def _iterate_column_groupbys(self, obj: DataFrame | Series):
for i, colname in enumerate(obj.columns):
Expand Down
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ def _compute_plot_data(self):
self.subplots = True
data = reconstruct_data_with_by(self.data, by=self.by, cols=self.columns)

# GH16953, _convert is needed as fallback, for ``Series``
# GH16953, infer_objects is needed as fallback, for ``Series``
# with ``dtype == object``
data = data._convert(datetime=True, timedelta=True)
data = data.infer_objects()
include_type = [np.number, "datetime", "datetimetz", "timedelta"]

# GH23719, allow plotting boolean
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _args_adjust(self) -> None:

def _calculate_bins(self, data: DataFrame) -> np.ndarray:
"""Calculate bins given data"""
nd_values = data._convert(datetime=True)._get_numeric_data()
nd_values = data.infer_objects()._get_numeric_data()
values = np.ravel(nd_values)
values = values[~isna(values)]

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test_apply_convert_objects():
}
)

result = expected.apply(lambda x: x, axis=1)._convert(datetime=True)
result = expected.apply(lambda x: x, axis=1)
tm.assert_frame_equal(result, expected)


Expand Down
42 changes: 0 additions & 42 deletions pandas/tests/frame/methods/test_convert.py

This file was deleted.

1 change: 0 additions & 1 deletion pandas/tests/io/pytables/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ def check_col(key, name, size):
df_dc.loc[df_dc.index[7:9], "string"] = "bar"
df_dc["string2"] = "cool"
df_dc["datetime"] = Timestamp("20010102")
df_dc = df_dc._convert(datetime=True)
df_dc.loc[df_dc.index[3:5], ["A", "B", "datetime"]] = np.nan

_maybe_remove(store, "df_dc")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_unimplemented_dtypes_table_columns(setup_path):
df["obj1"] = "foo"
df["obj2"] = "bar"
df["datetime1"] = datetime.date(2001, 1, 2)
df = df._consolidate()._convert(datetime=True)
df = df._consolidate()

with ensure_clean_store(setup_path) as store:
# this fails because we have a date in the object block......
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/test_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_put_mixed_type(setup_path):
df["datetime1"] = datetime.datetime(2001, 1, 2, 0, 0)
df["datetime2"] = datetime.datetime(2001, 1, 3, 0, 0)
df.loc[df.index[3:6], ["obj1"]] = np.nan
df = df._consolidate()._convert(datetime=True)
df = df._consolidate()

with ensure_clean_store(setup_path) as store:
_maybe_remove(store, "df")
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_repr(setup_path):
df["datetime1"] = datetime.datetime(2001, 1, 2, 0, 0)
df["datetime2"] = datetime.datetime(2001, 1, 3, 0, 0)
df.loc[df.index[3:6], ["obj1"]] = np.nan
df = df._consolidate()._convert(datetime=True)
df = df._consolidate()

with catch_warnings(record=True):
simplefilter("ignore", pd.errors.PerformanceWarning)
Expand Down Expand Up @@ -444,7 +444,7 @@ def test_table_mixed_dtypes(setup_path):
df["datetime1"] = datetime.datetime(2001, 1, 2, 0, 0)
df["datetime2"] = datetime.datetime(2001, 1, 3, 0, 0)
df.loc[df.index[3:6], ["obj1"]] = np.nan
df = df._consolidate()._convert(datetime=True)
df = df._consolidate()

with ensure_clean_store(setup_path) as store:
store.append("df1_mixed", df)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def try_remove_ws(x):
]
dfnew = df.applymap(try_remove_ws).replace(old, new)
gtnew = ground_truth.applymap(try_remove_ws)
converted = dfnew._convert(datetime=True)
converted = dfnew
date_cols = ["Closing Date", "Updated Date"]
converted[date_cols] = converted[date_cols].apply(to_datetime)
tm.assert_frame_equal(converted, gtnew)
Expand Down
94 changes: 0 additions & 94 deletions pandas/tests/series/methods/test_convert.py

This file was deleted.