Skip to content
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

remove undesired values kwarg #27625

Merged
merged 1 commit into from
Jul 31, 2019
Merged
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
63 changes: 30 additions & 33 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ def f(m, v, i):

return self.split_and_operate(None, f, False)

def astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
return self._astype(dtype, copy=copy, errors=errors, values=values, **kwargs)
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
def astype(self, dtype, copy=False, errors="raise", **kwargs):
return self._astype(dtype, copy=copy, errors=errors, **kwargs)

def _astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
def _astype(self, dtype, copy=False, errors="raise", **kwargs):
"""Coerce to the new type

Parameters
Expand Down Expand Up @@ -616,42 +616,39 @@ def _astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
return self.copy()
return self

if values is None:
try:
# force the copy here
if self.is_extension:
values = self.values.astype(dtype)
else:
if issubclass(dtype.type, str):

# use native type formatting for datetime/tz/timedelta
if self.is_datelike:
values = self.to_native_types()
try:
# force the copy here
if self.is_extension:
values = self.values.astype(dtype)
else:
if issubclass(dtype.type, str):

# astype formatting
else:
values = self.get_values()
# use native type formatting for datetime/tz/timedelta
if self.is_datelike:
values = self.to_native_types()

# astype formatting
else:
values = self.get_values(dtype=dtype)
values = self.get_values()

# _astype_nansafe works fine with 1-d only
vals1d = values.ravel()
values = astype_nansafe(vals1d, dtype, copy=True, **kwargs)
else:
values = self.get_values(dtype=dtype)

# TODO(extension)
# should we make this attribute?
if isinstance(values, np.ndarray):
values = values.reshape(self.shape)
# _astype_nansafe works fine with 1-d only
vals1d = values.ravel()
values = astype_nansafe(vals1d, dtype, copy=True, **kwargs)

except Exception:
# e.g. astype_nansafe can fail on object-dtype of strings
# trying to convert to float
if errors == "raise":
raise
newb = self.copy() if copy else self
else:
newb = make_block(values, placement=self.mgr_locs, ndim=self.ndim)
# TODO(extension)
# should we make this attribute?
if isinstance(values, np.ndarray):
values = values.reshape(self.shape)

except Exception:
# e.g. astype_nansafe can fail on object-dtype of strings
# trying to convert to float
if errors == "raise":
raise
newb = self.copy() if copy else self
else:
newb = make_block(values, placement=self.mgr_locs, ndim=self.ndim)

Expand Down