Skip to content

Commit f0086d7

Browse files
committed
Fix tz-aware comparison in plot() causing failures at DST boundary
1 parent 52972f4 commit f0086d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/plotting/_matplotlib/timeseries.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,14 @@ def use_dynamic_x(ax: Axes, index: Index) -> bool:
251251
return index[:1].is_normalized
252252
period = Period(index[0], freq_str)
253253
assert isinstance(period, Period)
254-
return period.to_timestamp().tz_localize(index.tz) == index[0]
254+
if index.tz is not None:
255+
# Compare naive local times directly
256+
period_naive = period.to_timestamp()
257+
index_naive = index[0].tz_localize(None) # Strips tz, keeps local time
258+
return period_naive == index_naive
259+
else:
260+
return period.to_timestamp() == index[0]
261+
255262
return True
256263

257264

0 commit comments

Comments
 (0)