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