From 5919f9d5fb0460348539b114d19f041012197c5a Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 31 Jul 2019 05:20:15 -0700 Subject: [PATCH] remove undesired values kwarg (#27625) --- pandas/core/internals/blocks.py | 63 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 62b08fd1712c8..86db4b0f82e25 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -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 @@ -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)