From 40fe569184e60b3a9ff9e9ece50026dd94d29a30 Mon Sep 17 00:00:00 2001 From: Dawid Makar Date: Tue, 26 Sep 2023 11:00:51 +0200 Subject: [PATCH] Automatic refactoring. Refactoring step id: UUID('65134aac-96bf-4d17-a48f-f7b9b0d9805d') --- pandas/core/arrays/arrow/array.py | 33 +++++++++---------------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 70c59e94f6d27..11e69f2cf0544 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -40,10 +40,7 @@ from pandas.core.dtypes.dtypes import DatetimeTZDtype from pandas.core.dtypes.missing import isna -from pandas.core import ( - missing, - roperator, -) +from pandas.core import roperator from pandas.core.arraylike import OpsMixin from pandas.core.arrays._arrow_string_mixins import ArrowStringArrayMixin from pandas.core.arrays.base import ( @@ -936,20 +933,6 @@ def pad_or_backfill( # TODO(CoW): Not necessary anymore when CoW is the default return self.copy() - if limit is not None and limit_area is not None: - method = missing.clean_fill_method(method) - try: - if method == "pad": - return type(self)(pc.fill_null_forward(self._pa_array)) - elif method == "backfill": - return type(self)(pc.fill_null_backward(self._pa_array)) - except pa.ArrowNotImplementedError: - # ArrowNotImplementedError: Function 'coalesce' has no kernel - # matching input types (duration[ns], duration[ns]) - # TODO: remove try/except wrapper if/when pyarrow implements - # a kernel for duration types. - pass - # TODO(3.0): after EA.fillna 'method' deprecation is enforced, we can remove # this method entirely. return super().pad_or_backfill( @@ -970,12 +953,9 @@ def fillna( # TODO(CoW): Not necessary anymore when CoW is the default return self.copy() - if limit is not None: + if limit is not None or method is not None: return super().fillna(value=value, method=method, limit=limit, copy=copy) - if method is not None: - return super().pad_or_backfill(method=method, limit=limit, copy=copy) - if isinstance(value, (np.ndarray, ExtensionArray)): # Similar to check_value_size, but we do not mask here since we may # end up passing it to the super() method. @@ -992,7 +972,12 @@ def fillna( raise TypeError(msg) from err try: - return type(self)(pc.fill_null(self._pa_array, fill_value=fill_value)) + if method is None: + return type(self)(pc.fill_null(self._pa_array, fill_value=fill_value)) + elif method == "pad": + return type(self)(pc.fill_null_forward(self._pa_array)) + elif method == "backfill": + return type(self)(pc.fill_null_backward(self._pa_array)) except pa.ArrowNotImplementedError: # ArrowNotImplementedError: Function 'coalesce' has no kernel # matching input types (duration[ns], duration[ns]) @@ -2568,4 +2553,4 @@ def transpose_homogeneous_pyarrow( indices = np.arange(nrows * ncols).reshape(ncols, nrows).T.flatten() arr = pa.chunked_array([chunk for arr in arrays for chunk in arr._pa_array.chunks]) arr = arr.take(indices) - return [ArrowExtensionArray(arr.slice(i * ncols, ncols)) for i in range(nrows)] + return [ArrowExtensionArray(arr.slice(i * ncols, ncols)) for i in range(nrows)] \ No newline at end of file