Skip to content

Commit 2de4d15

Browse files
typo, comments, improve test exception handling
1 parent 194caf5 commit 2de4d15

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Categorical
136136
Datetimelike
137137
^^^^^^^^^^^^
138138

139-
- Bug with :class:`Timestamp` and :class:`CustomBusinessDay` arithmatic throwing an exception with datetime subclasses (:issue:`25734`)
139+
- Bug with :class:`Timestamp` and :class:`CustomBusinessDay` arithmetic throwing an exception with datetime subclasses (:issue:`25734`)
140140
-
141141
-
142142

pandas/_libs/tslibs/conversion.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
384384
obj.value += ts.nanosecond
385385
obj.dts.ps = ts.nanosecond * 1000
386386
except AttributeError:
387+
# probably a subclass of datetime
387388
pass
388389

389390
if nanos:
@@ -613,6 +614,7 @@ cpdef inline datetime localize_pydatetime(datetime dt, object tz):
613614
try:
614615
return dt.tz_localize(tz)
615616
except AttributeError:
617+
# probably a subclass of datetime
616618
pass
617619
elif is_utc(tz):
618620
return _localize_pydatetime(dt, tz)

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,8 +2369,11 @@ class FakeDatetime(MetaDatetime("NewBase", (datetime,), {})):
23692369
with monkeypatch.context() as m:
23702370
# monkeypatch datetime everywhere
23712371
for mod_name, module in list(sys.modules.items()):
2372-
if (mod_name == __name__ or
2373-
module.__name__ in ('datetime',)):
2372+
try:
2373+
if (mod_name == __name__ or
2374+
module.__name__ in ('datetime',)):
2375+
continue
2376+
except AttributeError:
23742377
continue
23752378
for attribute_name in dir(module):
23762379
try:

0 commit comments

Comments
 (0)