Skip to content

Commit 58a7698

Browse files
PERF: check first for recognized scalars in DatetimeArray._validate_scalar (#44608)
1 parent 75d0a96 commit 58a7698

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,10 @@ def _validate_scalar(
635635
-------
636636
self._scalar_type or NaT
637637
"""
638-
if isinstance(value, str):
638+
if isinstance(value, self._scalar_type):
639+
pass
640+
641+
elif isinstance(value, str):
639642
# NB: Careful about tzawareness
640643
try:
641644
value = self._scalar_from_string(value)

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def _check_compatible_with(self, other, setitem: bool = False):
508508
self._assert_tzawareness_compat(other)
509509
if setitem:
510510
# Stricter check for setitem vs comparison methods
511-
if not timezones.tz_compare(self.tz, other.tz):
511+
if self.tz is not None and not timezones.tz_compare(self.tz, other.tz):
512512
# TODO(2.0): remove this check. GH#37605
513513
warnings.warn(
514514
"Setitem-like behavior with mismatched timezones is deprecated "

0 commit comments

Comments
 (0)