Skip to content

modified changes for datetime and NaT Objects Behavior closes #43280 #43289

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions pandas/core/tools/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ def to_numeric(arg, errors="raise", downcast=None):
if is_numeric_dtype(values_dtype):
pass
elif is_datetime_or_timedelta_dtype(values_dtype):
values = values.view(np.int64)
if pd.isnull(arg.values):
values = np.nan
else:
values = pd.to_datetime(values).strftime("%Y%m%d").astype(np.int64)
else:
values = ensure_object(values)
coerce_numeric = errors not in ("ignore", "raise")
Expand Down Expand Up @@ -236,7 +239,5 @@ def to_numeric(arg, errors="raise", downcast=None):
# because we want to coerce to numeric if possible,
# do not use _shallow_copy
return pd.Index(values, name=arg.name)
elif is_scalars:
return values[0]
else:
return values
return values[0]