Skip to content

CLN: remove unnecesary cast.maybe_convert_objects #38144

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
Nov 29, 2020
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
52 changes: 0 additions & 52 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
from pandas import Series
from pandas.core.arrays import ExtensionArray
from pandas.core.indexes.base import Index
from pandas.core.indexes.datetimes import DatetimeIndex

_int8_max = np.iinfo(np.int8).max
_int16_max = np.iinfo(np.int16).max
Expand Down Expand Up @@ -1121,57 +1120,6 @@ def astype_nansafe(
return arr.view(dtype)


def maybe_convert_objects(
values: np.ndarray, convert_numeric: bool = True
) -> Union[np.ndarray, "DatetimeIndex"]:
"""
If we have an object dtype array, try to coerce dates and/or numbers.

Parameters
----------
values : ndarray
convert_numeric : bool, default True

Returns
-------
ndarray or DatetimeIndex
"""
validate_bool_kwarg(convert_numeric, "convert_numeric")

orig_values = values

# convert dates
if is_object_dtype(values.dtype):
values = lib.maybe_convert_objects(values, convert_datetime=True)

# convert timedeltas
if is_object_dtype(values.dtype):
values = lib.maybe_convert_objects(values, convert_timedelta=True)

# convert to numeric
if is_object_dtype(values.dtype):
if convert_numeric:
try:
new_values = lib.maybe_convert_numeric(
values, set(), coerce_numeric=True
)
except (ValueError, TypeError):
pass
else:
# if we are all nans then leave me alone
if not isna(new_values).all():
values = new_values

else:
# soft-conversion
values = lib.maybe_convert_objects(values)

if values is orig_values:
values = values.copy()

return values


def soft_convert_objects(
values: np.ndarray,
datetime: bool = True,
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
find_common_type,
maybe_cast_result,
maybe_cast_result_dtype,
maybe_convert_objects,
maybe_downcast_numeric,
)
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -1867,8 +1866,9 @@ def _recast_datetimelike_result(result: DataFrame) -> DataFrame:

# See GH#26285
for n in obj_cols:
converted = maybe_convert_objects(
result.iloc[:, n].values, convert_numeric=False
values = result.iloc[:, n].values
converted = lib.maybe_convert_objects(
values, convert_datetime=True, convert_timedelta=True
)

result.iloc[:, n] = converted
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/dtypes/cast/test_convert_objects.py

This file was deleted.