@@ -529,6 +529,7 @@ def test_hf_text_and_hf_hovertext():
529
529
def test_multiple_timezones ():
530
530
n = 5_050
531
531
532
+ # NOTE: date-range returns a (tz-aware) DatetimeIndex
532
533
dr = pd .date_range ("2022-02-14" , freq = "s" , periods = n , tz = "UTC" )
533
534
dr_v = np .random .randn (n )
534
535
@@ -538,6 +539,12 @@ def test_multiple_timezones():
538
539
dr .tz_convert ("Europe/Brussels" ),
539
540
dr .tz_convert ("Australia/Perth" ),
540
541
dr .tz_convert ("Australia/Canberra" ),
542
+ # NOTE: this pd.Series tests the functionality of a Pandas series with (tz-aware) DatetimeIndex
543
+ pd .Series (dr ),
544
+ pd .Series (dr .tz_localize (None ).tz_localize ("Europe/Amsterdam" )),
545
+ pd .Series (dr .tz_convert ("Europe/Brussels" )),
546
+ pd .Series (dr .tz_convert ("Australia/Perth" )),
547
+ pd .Series (dr .tz_convert ("Australia/Canberra" )),
541
548
]
542
549
543
550
plain_plotly_fig = make_subplots (rows = len (cs ), cols = 1 , shared_xaxes = True )
@@ -564,7 +571,60 @@ def test_multiple_timezones():
564
571
col = 1 ,
565
572
)
566
573
# Assert that the time parsing is exactly the same
567
- assert plain_plotly_fig .data [0 ].x [0 ] == fr_fig .data [0 ].x [0 ]
574
+ assert plain_plotly_fig .data [i - 1 ].x [0 ] == fr_fig .data [i - 1 ].x [0 ]
575
+
576
+
577
+ def test_set_hfx_tz_aware_series ():
578
+ df = pd .DataFrame (
579
+ {
580
+ "timestamp" : pd .date_range (
581
+ "2020-01-01" , "2020-01-02" , freq = "1s"
582
+ ).tz_localize ("Asia/Seoul" )
583
+ }
584
+ )
585
+ df ["value" ] = np .random .randn (len (df ))
586
+
587
+ fr = FigureResampler ()
588
+ fr .add_trace ({}, hf_x = pd .Index (df .timestamp ), hf_y = df .value )
589
+ assert isinstance (fr .hf_data [0 ]["x" ], pd .DatetimeIndex )
590
+ # Now we set the pd.Series as hf_x
591
+ fr .hf_data [0 ]["x" ] = df .timestamp
592
+ assert not isinstance (fr .hf_data [0 ]["x" ], pd .DatetimeIndex )
593
+ # perform an update
594
+ out = fr .construct_update_data ({"xaxis.autorange" : True , "xaxis.showspikes" : False })
595
+ assert len (out ) == 2
596
+ # assert that the update was performed correctly
597
+ assert isinstance (fr .hf_data [0 ]["x" ], pd .DatetimeIndex )
598
+ assert all (fr .hf_data [0 ]["x" ] == pd .DatetimeIndex (df .timestamp ))
599
+
600
+
601
+ def test_datetime_hf_x_no_index_ ():
602
+ df = pd .DataFrame (
603
+ {"timestamp" : pd .date_range ("2020-01-01" , "2020-01-02" , freq = "1s" )}
604
+ )
605
+ df ["value" ] = np .random .randn (len (df ))
606
+
607
+ # add via hf_x kwargs
608
+ fr = FigureResampler ()
609
+ fr .add_trace ({}, hf_x = df .timestamp , hf_y = df .value )
610
+ output = fr .construct_update_data (
611
+ {
612
+ "xaxis.range[0]" : "2020-01-01 00:00:00" ,
613
+ "xaxis.range[1]" : "2020-01-01 00:00:20" ,
614
+ }
615
+ )
616
+ assert len (output ) == 2
617
+
618
+ # add via scatter kwargs
619
+ fr = FigureResampler ()
620
+ fr .add_trace (go .Scatter (x = df .timestamp , y = df .value ))
621
+ output = fr .construct_update_data (
622
+ {
623
+ "xaxis.range[0]" : "2020-01-01 00:00:00" ,
624
+ "xaxis.range[1]" : "2020-01-01 00:00:20" ,
625
+ }
626
+ )
627
+ assert len (output ) == 2
568
628
569
629
570
630
def test_datetime_hf_x_no_index ():
0 commit comments