@@ -758,6 +758,53 @@ def test_tz_xaxis_range():
758
758
assert len (out [2 ]["x" ]) == 2000
759
759
760
760
761
+ def test_compare_tz_with_fixed_offset ():
762
+ # related: https://github.com/predict-idlab/plotly-resampler/issues/305
763
+ fig = FigureResampler ()
764
+
765
+ x = pd .date_range ("2024-04-01T00:00:00" , "2025-01-01T00:00:00" , freq = "H" )
766
+ x = x .tz_localize ("Asia/Taipei" )
767
+ y = np .random .randn (len (x ))
768
+
769
+ fig .add_trace (
770
+ go .Scattergl (x = x , y = y , name = "demo" , mode = "lines+markers" ),
771
+ max_n_samples = int (len (x ) * 0.2 ),
772
+ )
773
+
774
+ relayout_data = {
775
+ "xaxis.range[0]" : "2024-04-27T08:00:00+08:00" ,
776
+ "xaxis.range[1]" : "2024-05-04T17:15:39.491031+08:00" ,
777
+ }
778
+
779
+ fig .construct_update_data_patch (relayout_data )
780
+
781
+
782
+ def test_compare_tz_with_fixed_offset_2 ():
783
+ # related: https://github.com/predict-idlab/plotly-resampler/issues/305
784
+ fig = FigureResampler ()
785
+
786
+ x = pd .date_range ("2024-04-01T00:00:00" , "2025-01-01T00:00:00" , freq = "H" )
787
+ x = x .tz_localize ("UTC" )
788
+ x = x .tz_convert ("Canada/Pacific" )
789
+ y = np .random .randn (len (x ))
790
+
791
+ fig .add_trace (
792
+ go .Scattergl (x = x , y = y , name = "demo" , mode = "lines+markers" ),
793
+ max_n_samples = int (len (x ) * 0.2 ),
794
+ )
795
+
796
+ relayout_data = {
797
+ "xaxis.range[0]" : pd .Timestamp ("2024-03-01T00:00:00" ).tz_localize (
798
+ "Canada/Pacific"
799
+ ),
800
+ "xaxis.range[1]" : pd .Timestamp ("2024-03-31T00:00:00" ).tz_localize (
801
+ "Canada/Pacific"
802
+ ),
803
+ }
804
+
805
+ fig .construct_update_data_patch (relayout_data )
806
+
807
+
761
808
def test_datetime_hf_x_no_index ():
762
809
df = pd .DataFrame (
763
810
{"timestamp" : pd .date_range ("2020-01-01" , "2020-01-02" , freq = "1s" )}
@@ -1013,7 +1060,7 @@ def test_time_tz_slicing_different_timestamp():
1013
1060
cs = [
1014
1061
dr ,
1015
1062
dr .tz_localize (None ).tz_localize ("Europe/Amsterdam" ),
1016
- dr .tz_convert ("Europe/Brussels " ),
1063
+ dr .tz_convert ("Europe/Lisbon " ),
1017
1064
dr .tz_convert ("Australia/Perth" ),
1018
1065
dr .tz_convert ("Australia/Canberra" ),
1019
1066
]
@@ -1031,6 +1078,26 @@ def test_time_tz_slicing_different_timestamp():
1031
1078
hf_data_dict , hf_data_dict ["axis_type" ], t_start , t_stop
1032
1079
)
1033
1080
1081
+ # THESE have the same timezone offset -> no AssertionError should be raised
1082
+ cs = [
1083
+ dr .tz_localize (None ).tz_localize ("Europe/Amsterdam" ),
1084
+ dr .tz_convert ("Europe/Brussels" ),
1085
+ dr .tz_convert ("Europe/Oslo" ),
1086
+ dr .tz_convert ("Europe/Paris" ),
1087
+ dr .tz_convert ("Europe/Rome" ),
1088
+ ]
1089
+
1090
+ for i , s in enumerate (cs ):
1091
+ t_start , t_stop = sorted (s .iloc [np .random .randint (0 , n , 2 )].index )
1092
+ t_start = t_start .tz_convert (cs [(i + 1 ) % len (cs )].index .tz )
1093
+ t_stop = t_stop .tz_convert (cs [(i + 1 ) % len (cs )].index .tz )
1094
+
1095
+ hf_data_dict = construct_hf_data_dict (s .index , s .values )
1096
+ start_idx , end_idx = PlotlyAggregatorParser .get_start_end_indices (
1097
+ hf_data_dict , hf_data_dict ["axis_type" ], t_start , t_stop
1098
+ )
1099
+
1100
+
1034
1101
1035
1102
def test_different_tz_no_tz_series_slicing ():
1036
1103
n = 60 * 60 * 24 * 3
0 commit comments