From 0b5adeb1901ab99eebf1966ab9018ab135291d18 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 11 Jul 2019 09:18:13 -0700 Subject: [PATCH 01/12] make _can_hold_element more accurate --- pandas/core/internals/blocks.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 1e84437f5c2fc..bc7f5e0cfa99b 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -10,6 +10,7 @@ from pandas._libs import NaT, lib, tslib, tslibs import pandas._libs.internals as libinternals from pandas._libs.tslibs import Timedelta, conversion, is_null_datetimelike +from pandas._libs.tslibs.timezones import tz_compare from pandas.util._validators import validate_bool_kwarg from pandas.core.dtypes.cast import ( @@ -2248,14 +2249,17 @@ def _astype(self, dtype, **kwargs): def _can_hold_element(self, element): tipo = maybe_infer_dtype_type(element) if tipo is not None: - return tipo == _NS_DTYPE or tipo == np.int64 + return is_dtype_equal(tipo, self.dtype) + elif element is NaT: + return True if isinstance(element, datetime): + if self.is_datetimetz: + return tz_compare(element.tzinfo, self.dtype.tz) return element.tzinfo is None if is_integer(element): return element == tslibs.iNaT - # TODO: shouldnt we exclude timedelta64("NaT")? See GH#27297 - return isna(element) + return isna(element) and not isinstance(element, np.timedelta64) def _coerce_values(self, values): return values.view("i8") @@ -2359,6 +2363,8 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock): is_datetimetz = True is_extension = True + _can_hold_element = DatetimeBlock._can_hold_element + @property def _holder(self): return DatetimeArray @@ -2606,12 +2612,12 @@ def _box_func(self): def _can_hold_element(self, element): tipo = maybe_infer_dtype_type(element) if tipo is not None: - return issubclass(tipo.type, (np.timedelta64, np.int64)) + return issubclass(tipo.type, np.timedelta64) if element is NaT: return True - return is_integer(element) or isinstance( - element, (timedelta, np.timedelta64, np.int64) - ) + if is_integer(element): + return element == tslibs.iNaT + return isinstance(element, (timedelta, np.timedelta64)) def fillna(self, value, **kwargs): @@ -2647,12 +2653,12 @@ def _try_coerce_args(self, other): base-type other """ - if is_null_datetimelike(other): + if is_null_datetimelike(other) and not isinstance(other, np.datetime64): other = tslibs.iNaT elif isinstance(other, (timedelta, np.timedelta64)): - other = Timedelta(other).value + other = Timedelta(other).to_timedelta64() elif hasattr(other, "dtype") and is_timedelta64_dtype(other): - other = other.astype("i8", copy=False).view("i8") + other = other.astype("i8", copy=False).view("m8[ns]") else: # coercion issues # let higher levels handle From e1f87032f9c1854af7365ee8bc4e5e35a2773e86 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 11 Jul 2019 12:10:21 -0700 Subject: [PATCH 02/12] Correctly accept None, np.nan, timedelta64(NaT) --- pandas/core/internals/blocks.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index bc7f5e0cfa99b..f89218a792df6 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1001,7 +1001,6 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0, transpose=False) or len(new) == 1 ): raise ValueError("cannot assign mismatch length to masked array") - np.putmask(new_values, mask, new) # maybe upcast me @@ -2613,11 +2612,13 @@ def _can_hold_element(self, element): tipo = maybe_infer_dtype_type(element) if tipo is not None: return issubclass(tipo.type, np.timedelta64) - if element is NaT: + elif element is NaT: return True - if is_integer(element): + elif isinstance(element, (timedelta, np.timedelta64)): + return True + elif is_integer(element): return element == tslibs.iNaT - return isinstance(element, (timedelta, np.timedelta64)) + return isna(element) and not isinstance(element, np.datetime64) def fillna(self, value, **kwargs): From 3663e221a75795df276616dae378f4f02a0b767c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 11 Jul 2019 13:46:44 -0700 Subject: [PATCH 03/12] revert m8 change --- pandas/core/internals/blocks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index cb74d3ac5c4eb..95a94a456785f 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1001,6 +1001,7 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0, transpose=False) or len(new) == 1 ): raise ValueError("cannot assign mismatch length to masked array") + np.putmask(new_values, mask, new) # maybe upcast me @@ -2657,9 +2658,9 @@ def _try_coerce_args(self, other): if is_null_datetimelike(other) and not isinstance(other, np.datetime64): other = tslibs.iNaT elif isinstance(other, (timedelta, np.timedelta64)): - other = Timedelta(other).to_timedelta64() + other = Timedelta(other).value elif hasattr(other, "dtype") and is_timedelta64_dtype(other): - other = other.astype("i8", copy=False).view("m8[ns]") + other = other.astype("i8", copy=False).view("i8") else: # coercion issues # let higher levels handle From 36c3b58b20b2c8e6e8f7b0286b7223e2774b33c5 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 11 Jul 2019 14:38:20 -0700 Subject: [PATCH 04/12] use is_valid_nat_for_dtype --- pandas/core/internals/blocks.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 95a94a456785f..6382cbcf626fc 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -61,7 +61,13 @@ ABCPandasArray, ABCSeries, ) -from pandas.core.dtypes.missing import _isna_compat, array_equivalent, isna, notna +from pandas.core.dtypes.missing import ( + _isna_compat, + array_equivalent, + is_valid_nat_for_dtype, + isna, + notna, +) import pandas.core.algorithms as algos from pandas.core.arrays import ( @@ -2259,7 +2265,7 @@ def _can_hold_element(self, element): elif is_integer(element): return element == tslibs.iNaT - return isna(element) and not isinstance(element, np.timedelta64) + return is_valid_nat_for_dtype(element, self.dtype) def _coerce_values(self, values): return values.view("i8") @@ -2619,7 +2625,7 @@ def _can_hold_element(self, element): return True elif is_integer(element): return element == tslibs.iNaT - return isna(element) and not isinstance(element, np.datetime64) + return is_valid_nat_for_dtype(element, self.dtype) def fillna(self, value, **kwargs): From e0f76a6742bcc13246c195725e89d633497ba9b1 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 11 Jul 2019 16:11:07 -0700 Subject: [PATCH 05/12] test_roundtrip_thru_setitem fix --- pandas/core/internals/blocks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 6382cbcf626fc..8ce2f12ca869c 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2618,7 +2618,9 @@ def _box_func(self): def _can_hold_element(self, element): tipo = maybe_infer_dtype_type(element) if tipo is not None: - return issubclass(tipo.type, np.timedelta64) + # TODO: remove the np.int64 support once coerce_values and + # _try_coerce_args both coerce to m8[ns] and not i8. + return issubclass(tipo.type, (np.timedelta64, np.int64)) elif element is NaT: return True elif isinstance(element, (timedelta, np.timedelta64)): From 06b54efb2ae7898ae183448d8968c1ecae66c153 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 12 Jul 2019 07:53:10 -0700 Subject: [PATCH 06/12] use is_valid_nat_for_dtype --- pandas/core/internals/blocks.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 8ce2f12ca869c..12ecd6ec3abd2 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -9,7 +9,7 @@ from pandas._libs import NaT, lib, tslib, tslibs import pandas._libs.internals as libinternals -from pandas._libs.tslibs import Timedelta, conversion, is_null_datetimelike +from pandas._libs.tslibs import Timedelta, conversion from pandas._libs.tslibs.timezones import tz_compare from pandas.util._validators import validate_bool_kwarg @@ -2285,7 +2285,7 @@ def _try_coerce_args(self, other): ------- base-type other """ - if is_null_datetimelike(other): + if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT elif isinstance(other, (datetime, np.datetime64, date)): other = self._box_func(other) @@ -2477,7 +2477,7 @@ def _try_coerce_args(self, other): # add the tz back other = self._holder(other, dtype=self.dtype) - elif is_null_datetimelike(other): + elif is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT elif isinstance(other, self._holder): if other.tz != self.values.tz: @@ -2663,7 +2663,7 @@ def _try_coerce_args(self, other): base-type other """ - if is_null_datetimelike(other) and not isinstance(other, np.datetime64): + if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT elif isinstance(other, (timedelta, np.timedelta64)): other = Timedelta(other).value From 7a54804ac0bc12b48cabd77f052d7af4abe2927b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 12 Jul 2019 09:03:09 -0700 Subject: [PATCH 07/12] allow iNaT through --- pandas/core/internals/blocks.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 12ecd6ec3abd2..9033a82c1fa34 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2287,6 +2287,8 @@ def _try_coerce_args(self, other): """ if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT + elif is_integer(other) and other == tslibs.iNaT: + pass elif isinstance(other, (datetime, np.datetime64, date)): other = self._box_func(other) if getattr(other, "tz") is not None: @@ -2479,6 +2481,8 @@ def _try_coerce_args(self, other): elif is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT + elif is_integer(other) and other == tslibs.iNaT: + pass elif isinstance(other, self._holder): if other.tz != self.values.tz: raise ValueError("incompatible or non tz-aware value") @@ -2665,6 +2669,8 @@ def _try_coerce_args(self, other): if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT + elif is_integer(other) and other == tslibs.iNaT: + pass elif isinstance(other, (timedelta, np.timedelta64)): other = Timedelta(other).value elif hasattr(other, "dtype") and is_timedelta64_dtype(other): From 07be36c949a966f744778c3ef03b93c8ff83115a Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 12 Jul 2019 09:43:27 -0700 Subject: [PATCH 08/12] scalar check --- pandas/core/dtypes/missing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 6a681954fd902..bea73d72b91c9 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -574,7 +574,7 @@ def is_valid_nat_for_dtype(obj, dtype): ------- bool """ - if not isna(obj): + if not lib.is_scalar(obj) or not isna(obj): return False if dtype.kind == "M": return not isinstance(obj, np.timedelta64) From 1b1d4d86925b3e48240f422471ec125c61e07e31 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 12 Jul 2019 17:08:44 -0700 Subject: [PATCH 09/12] avoid np deprecation warnings that raise in npdev --- pandas/core/internals/blocks.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 9033a82c1fa34..5c6449f94985f 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2262,7 +2262,7 @@ def _can_hold_element(self, element): if self.is_datetimetz: return tz_compare(element.tzinfo, self.dtype.tz) return element.tzinfo is None - elif is_integer(element): + elif is_integer(element) and not isinstance(element, np.timedelta64): return element == tslibs.iNaT return is_valid_nat_for_dtype(element, self.dtype) @@ -2287,7 +2287,11 @@ def _try_coerce_args(self, other): """ if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif is_integer(other) and other == tslibs.iNaT: + elif ( + is_integer(other) + and not isinstance(other, np.timedelta64) + and other == tslibs.iNaT + ): pass elif isinstance(other, (datetime, np.datetime64, date)): other = self._box_func(other) @@ -2481,7 +2485,11 @@ def _try_coerce_args(self, other): elif is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif is_integer(other) and other == tslibs.iNaT: + elif ( + is_integer(other) + and not isinstance(other, np.timedelta64) + and other == tslibs.iNaT + ): pass elif isinstance(other, self._holder): if other.tz != self.values.tz: @@ -2669,7 +2677,11 @@ def _try_coerce_args(self, other): if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif is_integer(other) and other == tslibs.iNaT: + elif ( + is_integer(other) + and not isinstance(other, np.timedelta64) + and other == tslibs.iNaT + ): pass elif isinstance(other, (timedelta, np.timedelta64)): other = Timedelta(other).value From 178dde6dcb7e6b34a2f8de441004aff8ee20a92e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 15 Jul 2019 08:30:30 -0700 Subject: [PATCH 10/12] implement is_integer_strict --- pandas/core/dtypes/common.py | 1 + pandas/core/dtypes/inference.py | 15 +++++++++++++++ pandas/core/internals/blocks.py | 23 ++++++----------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index d0e4bd9b4482a..06d8e2fc06a5e 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -35,6 +35,7 @@ is_float, is_hashable, is_integer, + is_integer_strict, is_interval, is_iterator, is_list_like, diff --git a/pandas/core/dtypes/inference.py b/pandas/core/dtypes/inference.py index 9373ea18e8a24..fc8ef20c2e0e6 100644 --- a/pandas/core/dtypes/inference.py +++ b/pandas/core/dtypes/inference.py @@ -24,6 +24,21 @@ is_interval = lib.is_interval +def is_integer_strict(obj) -> bool: + """ + Check if the object is an integer, excluding timedelta64 objects. + + Parameters + ---------- + obj : object + + Returns + ------- + bool + """ + return is_integer(obj) and not isinstance(obj, np.timedelta64) + + def is_number(obj): """ Check if the object is a number. diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 5c6449f94985f..e52c92e0fd7a1 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -40,6 +40,7 @@ is_float_dtype, is_integer, is_integer_dtype, + is_integer_strict, is_interval_dtype, is_list_like, is_numeric_v_string_like, @@ -2262,7 +2263,7 @@ def _can_hold_element(self, element): if self.is_datetimetz: return tz_compare(element.tzinfo, self.dtype.tz) return element.tzinfo is None - elif is_integer(element) and not isinstance(element, np.timedelta64): + elif is_integer_strict(element): return element == tslibs.iNaT return is_valid_nat_for_dtype(element, self.dtype) @@ -2287,11 +2288,7 @@ def _try_coerce_args(self, other): """ if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif ( - is_integer(other) - and not isinstance(other, np.timedelta64) - and other == tslibs.iNaT - ): + elif is_integer_strict(other) and other == tslibs.iNaT: pass elif isinstance(other, (datetime, np.datetime64, date)): other = self._box_func(other) @@ -2485,11 +2482,7 @@ def _try_coerce_args(self, other): elif is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif ( - is_integer(other) - and not isinstance(other, np.timedelta64) - and other == tslibs.iNaT - ): + elif is_integer_strict(other) and other == tslibs.iNaT: pass elif isinstance(other, self._holder): if other.tz != self.values.tz: @@ -2637,7 +2630,7 @@ def _can_hold_element(self, element): return True elif isinstance(element, (timedelta, np.timedelta64)): return True - elif is_integer(element): + elif is_integer_strict(element): return element == tslibs.iNaT return is_valid_nat_for_dtype(element, self.dtype) @@ -2677,11 +2670,7 @@ def _try_coerce_args(self, other): if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif ( - is_integer(other) - and not isinstance(other, np.timedelta64) - and other == tslibs.iNaT - ): + elif is_integer_strict(other) and other == tslibs.iNaT: pass elif isinstance(other, (timedelta, np.timedelta64)): other = Timedelta(other).value From a126c3ba11516e2469264620f157d484a285a6a3 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 15 Jul 2019 09:36:25 -0700 Subject: [PATCH 11/12] revert is_integer_strict --- pandas/core/dtypes/common.py | 1 - pandas/core/dtypes/inference.py | 15 --------------- pandas/core/internals/blocks.py | 23 +++++++++++++++++------ 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 06d8e2fc06a5e..d0e4bd9b4482a 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -35,7 +35,6 @@ is_float, is_hashable, is_integer, - is_integer_strict, is_interval, is_iterator, is_list_like, diff --git a/pandas/core/dtypes/inference.py b/pandas/core/dtypes/inference.py index fc8ef20c2e0e6..9373ea18e8a24 100644 --- a/pandas/core/dtypes/inference.py +++ b/pandas/core/dtypes/inference.py @@ -24,21 +24,6 @@ is_interval = lib.is_interval -def is_integer_strict(obj) -> bool: - """ - Check if the object is an integer, excluding timedelta64 objects. - - Parameters - ---------- - obj : object - - Returns - ------- - bool - """ - return is_integer(obj) and not isinstance(obj, np.timedelta64) - - def is_number(obj): """ Check if the object is a number. diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index e52c92e0fd7a1..217d6ba4ffa4a 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -40,7 +40,6 @@ is_float_dtype, is_integer, is_integer_dtype, - is_integer_strict, is_interval_dtype, is_list_like, is_numeric_v_string_like, @@ -2263,7 +2262,7 @@ def _can_hold_element(self, element): if self.is_datetimetz: return tz_compare(element.tzinfo, self.dtype.tz) return element.tzinfo is None - elif is_integer_strict(element): + elif is_integer(element) and not isinstance(element, np.timedelta64): return element == tslibs.iNaT return is_valid_nat_for_dtype(element, self.dtype) @@ -2288,7 +2287,11 @@ def _try_coerce_args(self, other): """ if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif is_integer_strict(other) and other == tslibs.iNaT: + elif ( + is_integer(other) + and not isinstance(other, np.timedelta64) + and other == tslibs.iNaT + ): pass elif isinstance(other, (datetime, np.datetime64, date)): other = self._box_func(other) @@ -2482,7 +2485,11 @@ def _try_coerce_args(self, other): elif is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif is_integer_strict(other) and other == tslibs.iNaT: + elif ( + is_integer(other) + and not isinstance(other, np.timedelta64) + and other == tslibs.iNaT + ): pass elif isinstance(other, self._holder): if other.tz != self.values.tz: @@ -2630,7 +2637,7 @@ def _can_hold_element(self, element): return True elif isinstance(element, (timedelta, np.timedelta64)): return True - elif is_integer_strict(element): + elif is_integer(element) and not isinstance(element, np.timedelta64): return element == tslibs.iNaT return is_valid_nat_for_dtype(element, self.dtype) @@ -2670,7 +2677,11 @@ def _try_coerce_args(self, other): if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif is_integer_strict(other) and other == tslibs.iNaT: + elif ( + is_integer(other) + and not isinstance(other, np.timedelta64) + and other == tslibs.iNaT + ): pass elif isinstance(other, (timedelta, np.timedelta64)): other = Timedelta(other).value From 2f3a0ed410d81b9421c87ca5588b86050f87f1ae Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 15 Jul 2019 11:39:15 -0700 Subject: [PATCH 12/12] update post is_integer fix --- pandas/core/internals/blocks.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index ac671aa8d13d3..e02fecf0ef114 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2262,7 +2262,7 @@ def _can_hold_element(self, element): if self.is_datetimetz: return tz_compare(element.tzinfo, self.dtype.tz) return element.tzinfo is None - elif is_integer(element) and not isinstance(element, np.timedelta64): + elif is_integer(element): return element == tslibs.iNaT return is_valid_nat_for_dtype(element, self.dtype) @@ -2287,11 +2287,7 @@ def _try_coerce_args(self, other): """ if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif ( - is_integer(other) - and not isinstance(other, np.timedelta64) - and other == tslibs.iNaT - ): + elif is_integer(other) and other == tslibs.iNaT: pass elif isinstance(other, (datetime, np.datetime64, date)): other = self._box_func(other) @@ -2485,11 +2481,7 @@ def _try_coerce_args(self, other): elif is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif ( - is_integer(other) - and not isinstance(other, np.timedelta64) - and other == tslibs.iNaT - ): + elif is_integer(other) and other == tslibs.iNaT: pass elif isinstance(other, self._holder): if other.tz != self.values.tz: @@ -2677,11 +2669,7 @@ def _try_coerce_args(self, other): if is_valid_nat_for_dtype(other, self.dtype): other = tslibs.iNaT - elif ( - is_integer(other) - and not isinstance(other, np.timedelta64) - and other == tslibs.iNaT - ): + elif is_integer(other) and other == tslibs.iNaT: pass elif isinstance(other, (timedelta, np.timedelta64)): other = Timedelta(other).value