Skip to content

Commit

Permalink
remove undesired values kwarg (#27625)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Jul 31, 2019
1 parent 854a89d commit 5919f9d
Showing 1 changed file with 30 additions and 33 deletions.
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)
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

0 comments on commit 5919f9d

Please sign in to comment.