From 0cb6af8212f1cd859a58c0070e4663d215918083 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 23 Sep 2020 10:43:46 +0200 Subject: [PATCH 1/9] remove redundant paranthesis --- pandas/core/arrays/sparse/array.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 528d78a5414ea..2cc872c0259eb 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1161,9 +1161,9 @@ def __setstate__(self, state): def nonzero(self): if self.fill_value == 0: - return (self.sp_index.to_int_index().indices,) + return self.sp_index.to_int_index().indices else: - return (self.sp_index.to_int_index().indices[self.sp_values != 0],) + return self.sp_index.to_int_index().indices[self.sp_values != 0] # ------------------------------------------------------------------------ # Reductions From 211ba7d3e773592fd000498a66c280cc40f884ef Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 23 Sep 2020 10:44:20 +0200 Subject: [PATCH 2/9] parameter copy not used --- pandas/core/arrays/sparse/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 2cc872c0259eb..d5bee0abee061 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -452,7 +452,7 @@ def from_spmatrix(cls, data): return cls._simple_new(arr, index, dtype) - def __array__(self, dtype=None, copy=True) -> np.ndarray: + def __array__(self, dtype=None) -> np.ndarray: fill_value = self.fill_value if self.sp_index.ngaps == 0: From 088265de03c098d89530141951d2faa974dd9060 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 23 Sep 2020 10:45:06 +0200 Subject: [PATCH 3/9] remove whitespace and unused argument --- pandas/core/arrays/sparse/array.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index d5bee0abee061..5180d18419181 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -677,7 +677,7 @@ def shift(self, periods=1, fill_value=None): a = empty b = arr[:-periods] else: - a = arr[abs(periods) :] + a = arr[abs(periods):] b = empty return arr._concat_same_type([a, b]) @@ -1515,7 +1515,7 @@ def _formatter(self, boxed=False): SparseArray._add_unary_ops() -def make_sparse(arr: np.ndarray, kind="block", fill_value=None, dtype=None, copy=False): +def make_sparse(arr: np.ndarray, kind="block", fill_value=None, dtype=None): """ Convert ndarray to sparse format From 4841e3b28bab28e410fcb5994ec4da9f26214e5b Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 23 Sep 2020 10:58:26 +0200 Subject: [PATCH 4/9] clean ups in general --- pandas/core/arrays/_arrow_utils.py | 2 +- pandas/core/arrays/base.py | 2 +- pandas/core/arrays/categorical.py | 2 +- pandas/core/arrays/datetimelike.py | 2 +- pandas/core/arrays/datetimes.py | 1 + pandas/core/arrays/interval.py | 4 ++-- pandas/core/arrays/period.py | 2 +- pandas/core/computation/parsing.py | 1 + pandas/core/computation/pytables.py | 4 +++- 9 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pandas/core/arrays/_arrow_utils.py b/pandas/core/arrays/_arrow_utils.py index c89f5554d0715..893eeb91ef582 100644 --- a/pandas/core/arrays/_arrow_utils.py +++ b/pandas/core/arrays/_arrow_utils.py @@ -26,7 +26,7 @@ def pyarrow_array_to_numpy_and_mask(arr, dtype): a boolean mask (validity mask, so False means missing) """ buflist = arr.buffers() - data = np.frombuffer(buflist[1], dtype=dtype)[arr.offset : arr.offset + len(arr)] + data = np.frombuffer(buflist[1], dtype=dtype)[arr.offset: arr.offset + len(arr)] bitmask = buflist[0] if bitmask is not None: mask = pyarrow.BooleanArray.from_buffers( diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index eae401f9744f0..390142837c5ec 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -687,7 +687,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> "ExtensionArray" a = empty b = self[:-periods] else: - a = self[abs(periods) :] + a = self[abs(periods):] b = empty return self._concat_same_type([a, b]) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 32ef37d44ad1b..835105b956469 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1767,7 +1767,7 @@ def _tidy_repr(self, max_vals=10, footer=True) -> str: """ num = max_vals // 2 head = self[:num]._get_repr(length=False, footer=False) - tail = self[-(max_vals - num) :]._get_repr(length=False, footer=False) + tail = self[-(max_vals - num):]._get_repr(length=False, footer=False) result = f"{head[:-1]}, ..., {tail[1:]}" if footer: diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 7051507f9a90e..fadcc5a4bd7da 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -1181,7 +1181,7 @@ def _add_timedelta_arraylike(self, other): self_i8, other_i8, arr_mask=self._isnan, b_mask=other._isnan ) if self._hasnans or other._hasnans: - mask = (self._isnan) | (other._isnan) + mask = self._isnan | other._isnan new_values[mask] = iNaT return type(self)(new_values, dtype=self.dtype) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index b1f98199f9fba..9e84292008856 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2018,6 +2018,7 @@ def objects_to_datetime64ns( utc : bool, default False Whether to convert timezone-aware timestamps to UTC. errors : {'raise', 'ignore', 'coerce'} + require_iso8601 : bool, default False allow_object : bool Whether to return an object-dtype ndarray instead of raising if the data contains more than one timezone. diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 1011381f235ca..76d2a4e776707 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -436,7 +436,7 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): ), ) ) - def from_tuples(cls, data, closed="right", copy=False, dtype=None): + def from_tuples(cls, data, closed="right", dtype=None): if len(data): left, right = [], [] else: @@ -758,7 +758,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> "IntervalArray": a = empty b = self[:-periods] else: - a = self[abs(periods) :] + a = self[abs(periods):] b = empty return self._concat_same_type([a, b]) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 372ef7df9dc3a..e5446901262ba 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -646,7 +646,7 @@ def _sub_period_array(self, other): new_values = np.array([self.freq.base * x for x in new_values]) if self._hasnans or other._hasnans: - mask = (self._isnan) | (other._isnan) + mask = self._isnan | other._isnan new_values[mask] = NaT return new_values diff --git a/pandas/core/computation/parsing.py b/pandas/core/computation/parsing.py index 86e125b6b909b..1fcd073c227fe 100644 --- a/pandas/core/computation/parsing.py +++ b/pandas/core/computation/parsing.py @@ -154,6 +154,7 @@ def tokenize_backtick_quoted_string( The token that represents the backtick quoted string. The integer is equal to BACKTICK_QUOTED_STRING (100). """ + string_end = None for _, tokval, start, _, _ in token_generator: if tokval == "`": string_end = start[1] diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index d876c655421ef..8332c223feab4 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -132,6 +132,8 @@ def pr(left, right): res = pr(left.value, right.prune(klass)) elif not (is_term(left) or is_term(right)): res = pr(left.prune(klass), right.prune(klass)) + else: + res = None return res @@ -445,7 +447,7 @@ def visit_Attribute(self, node, **kwargs): # try to get the value to see if we are another expression try: resolved = resolved.value - except (AttributeError): + except AttributeError: pass try: From e60ca48f2f39da76c9fb78193c7a984f25e82132 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Thu, 24 Sep 2020 22:46:32 +0200 Subject: [PATCH 5/9] changes black --- pandas/core/arrays/_arrow_utils.py | 2 +- pandas/core/arrays/base.py | 2 +- pandas/core/arrays/categorical.py | 2 +- pandas/core/arrays/interval.py | 2 +- pandas/core/arrays/sparse/array.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/arrays/_arrow_utils.py b/pandas/core/arrays/_arrow_utils.py index 893eeb91ef582..c89f5554d0715 100644 --- a/pandas/core/arrays/_arrow_utils.py +++ b/pandas/core/arrays/_arrow_utils.py @@ -26,7 +26,7 @@ def pyarrow_array_to_numpy_and_mask(arr, dtype): a boolean mask (validity mask, so False means missing) """ buflist = arr.buffers() - data = np.frombuffer(buflist[1], dtype=dtype)[arr.offset: arr.offset + len(arr)] + data = np.frombuffer(buflist[1], dtype=dtype)[arr.offset : arr.offset + len(arr)] bitmask = buflist[0] if bitmask is not None: mask = pyarrow.BooleanArray.from_buffers( diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 390142837c5ec..eae401f9744f0 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -687,7 +687,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> "ExtensionArray" a = empty b = self[:-periods] else: - a = self[abs(periods):] + a = self[abs(periods) :] b = empty return self._concat_same_type([a, b]) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 835105b956469..32ef37d44ad1b 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1767,7 +1767,7 @@ def _tidy_repr(self, max_vals=10, footer=True) -> str: """ num = max_vals // 2 head = self[:num]._get_repr(length=False, footer=False) - tail = self[-(max_vals - num):]._get_repr(length=False, footer=False) + tail = self[-(max_vals - num) :]._get_repr(length=False, footer=False) result = f"{head[:-1]}, ..., {tail[1:]}" if footer: diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 76d2a4e776707..dbb155f3188bc 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -758,7 +758,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> "IntervalArray": a = empty b = self[:-periods] else: - a = self[abs(periods):] + a = self[abs(periods) :] b = empty return self._concat_same_type([a, b]) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 5180d18419181..c2baaf55e27fe 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -677,7 +677,7 @@ def shift(self, periods=1, fill_value=None): a = empty b = arr[:-periods] else: - a = arr[abs(periods):] + a = arr[abs(periods) :] b = empty return arr._concat_same_type([a, b]) From 6d33c8983795b3ea8aa323df0dd13d69f98fbf96 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 3 Oct 2020 13:37:53 +0200 Subject: [PATCH 6/9] revert changes --- pandas/core/arrays/interval.py | 2 +- pandas/core/arrays/sparse/array.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 6ea8768e0cfbb..413430942575d 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -451,7 +451,7 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): ), ) ) - def from_tuples(cls, data, closed="right", dtype=None): + def from_tuples(cls, data, closed="right", copy=False, dtype=None): if len(data): left, right = [], [] else: diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 2f972439d4b65..d4ec641794fc2 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1161,9 +1161,9 @@ def __setstate__(self, state): def nonzero(self): if self.fill_value == 0: - return self.sp_index.to_int_index().indices + return (self.sp_index.to_int_index().indices,) else: - return self.sp_index.to_int_index().indices[self.sp_values != 0] + return (self.sp_index.to_int_index().indices[self.sp_values != 0],) # ------------------------------------------------------------------------ # Reductions From 8ec702eed1d7e80ed6cca000ee90c85ef503e605 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 3 Oct 2020 13:40:44 +0200 Subject: [PATCH 7/9] close if elif with else --- pandas/core/computation/pytables.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 8332c223feab4..10f401f3430f8 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -130,10 +130,8 @@ def pr(left, right): res = pr(left.prune(klass), right.value) elif is_term(left) and not is_term(right): res = pr(left.value, right.prune(klass)) - elif not (is_term(left) or is_term(right)): + else: # not (is_term(left) or is_term(right)): res = pr(left.prune(klass), right.prune(klass)) - else: - res = None return res From 2f6b2d107b55ce64a2f12753f757937eecbb0ef6 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 5 Oct 2020 00:45:41 +0200 Subject: [PATCH 8/9] revert pytables --- pandas/core/computation/pytables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 10f401f3430f8..d876c655421ef 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -130,7 +130,7 @@ def pr(left, right): res = pr(left.prune(klass), right.value) elif is_term(left) and not is_term(right): res = pr(left.value, right.prune(klass)) - else: # not (is_term(left) or is_term(right)): + elif not (is_term(left) or is_term(right)): res = pr(left.prune(klass), right.prune(klass)) return res @@ -445,7 +445,7 @@ def visit_Attribute(self, node, **kwargs): # try to get the value to see if we are another expression try: resolved = resolved.value - except AttributeError: + except (AttributeError): pass try: From ad29307f4af64445f4b4b7c9003eeeaae56ae863 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 5 Oct 2020 01:08:36 +0200 Subject: [PATCH 9/9] revert parsin --- pandas/core/computation/parsing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/computation/parsing.py b/pandas/core/computation/parsing.py index 1fcd073c227fe..86e125b6b909b 100644 --- a/pandas/core/computation/parsing.py +++ b/pandas/core/computation/parsing.py @@ -154,7 +154,6 @@ def tokenize_backtick_quoted_string( The token that represents the backtick quoted string. The integer is equal to BACKTICK_QUOTED_STRING (100). """ - string_end = None for _, tokval, start, _, _ in token_generator: if tokval == "`": string_end = start[1]