Skip to content

Commit 90d2251

Browse files
authored
Figurewidget datetime bug (#232)
* 💨 adding tests for #231 * 🙈 formatting * 🙏 bugfix * 💪 fixing 🐛
1 parent c905478 commit 90d2251

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@ def _parse_get_trace_props(
600600
# If we cast a tz-aware datetime64 array to `.values` we lose the tz-info
601601
# and the UTC time will be displayed instead of the tz-localized time,
602602
# hence we cast to a pd.DatetimeIndex, which preserves the tz-info
603-
else pd.Index(hf_x) if pd.core.dtypes.common.is_datetime64tz_dtype(hf_x)
603+
# As a matter of fact, to resolve #231, we also convert non-tz-aware
604+
# datetime64 arrays to an pd.Index
605+
else pd.Index(hf_x) if pd.core.dtypes.common.is_datetime64_any_dtype(hf_x)
604606
else hf_x.values if isinstance(hf_x, pd.Series)
605607
else hf_x if isinstance(hf_x, pd.Index)
606608
else np.asarray(hf_x)

tests/test_figure_resampler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ def test_datetime_hf_x_no_index():
786786
}
787787
)
788788
assert len(output) == 2
789+
assert isinstance(output[1]["x"], pd.Index)
789790

790791
# add via scatter kwargs
791792
fr = FigureResampler()
@@ -797,6 +798,7 @@ def test_datetime_hf_x_no_index():
797798
}
798799
)
799800
assert len(output) == 2
801+
assert isinstance(output[1]["x"], pd.Index)
800802

801803

802804
def test_multiple_timezones_in_single_x_index__datetimes_and_timestamps():

tests/test_figurewidget_resampler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def test_datetime_hf_x_no_index():
548548
}
549549
)
550550
assert len(output) == 2
551+
assert isinstance(output[1]["x"], pd.Index)
551552

552553
# add via scatter kwargs
553554
fr = FigureWidgetResampler()
@@ -559,6 +560,7 @@ def test_datetime_hf_x_no_index():
559560
}
560561
)
561562
assert len(output) == 2
563+
assert isinstance(output[1]["x"], pd.Index)
562564

563565

564566
def test_multiple_timezones_in_single_x_index__datetimes_and_timestamps():

0 commit comments

Comments
 (0)