@@ -646,7 +646,7 @@ def test_datapoints_no_names(self) -> None:
646646
647647 d = Datapoints (id = 1 , is_string = False , is_step = False , type = "numeric" , timestamp = [1 , 2 , 3 ], average = [2 , 3 , 4 ])
648648 expected_df = pd .DataFrame ({1 : [2 , 3 , 4.0 ]}, index = pd .to_datetime (range (1 , 4 ), unit = "ms" ))
649- expected_df .columns = pd .MultiIndex . from_tuples ([( 1 ,) ], names = [ "identifier" ] )
649+ expected_df .columns = pd .Index ([ 1 ], name = "identifier" )
650650 pd .testing .assert_frame_equal (expected_df , d .to_pandas (include_aggregate_name = False ))
651651
652652 expected_df = pd .DataFrame ({1 : [2 , 3 , 4.0 ]}, index = pd .to_datetime (range (1 , 4 ), unit = "ms" ))
@@ -676,6 +676,40 @@ def test_id_and_external_id_set_gives_external_id_columns(self) -> None:
676676 )
677677 pd .testing .assert_frame_equal (expected_df , d .to_pandas ())
678678
679+ def test_raw_datapoints_external_id_gives_plain_index (self ) -> None :
680+ import pandas as pd
681+
682+ d = Datapoints (
683+ id = 1 ,
684+ external_id = "my-ts" ,
685+ is_string = False ,
686+ is_step = False ,
687+ type = "numeric" ,
688+ timestamp = [1 , 2 ],
689+ value = [3.0 , 4.0 ],
690+ )
691+ df = d .to_pandas ()
692+ assert isinstance (df .columns , pd .Index ) and not isinstance (df .columns , pd .MultiIndex )
693+ assert list (df .columns ) == ["my-ts" ]
694+
695+ def test_raw_datapoints_with_status_codes_gives_multi_index (self ) -> None :
696+ import pandas as pd
697+
698+ d = Datapoints (
699+ id = 1 ,
700+ external_id = "my-ts" ,
701+ is_string = False ,
702+ is_step = False ,
703+ type = "numeric" ,
704+ timestamp = [1 , 2 ],
705+ value = [3.0 , 4.0 ],
706+ status_code = [0 , 0 ],
707+ status_symbol = ["Good" , "Good" ],
708+ )
709+ df = d .to_pandas ()
710+ assert isinstance (df .columns , pd .MultiIndex )
711+ assert df .columns .names == ["identifier" , "status" ]
712+
679713 def test_datapoints_empty (self ) -> None :
680714 d = Datapoints (id = 0 , is_string = False , is_step = False , type = "numeric" , external_id = "1" , timestamp = [], value = [])
681715 assert d .to_pandas ().empty
@@ -729,7 +763,7 @@ def test_datapoints_list_names(self) -> None:
729763 expected_df = pd .DataFrame ({1 : [2 , 3 , 4.0 ], 2 : [1 , None , 3 ]}, index = pd .to_datetime (range (1 , 4 ), unit = "ms" ))
730764 expected_df .columns = pd .MultiIndex .from_tuples ([(2 , "max" ), (3 , "average" )], names = ["identifier" , "aggregate" ])
731765 pd .testing .assert_frame_equal (expected_df , dps_list .to_pandas (), check_freq = False )
732- expected_df .columns = pd .MultiIndex . from_tuples ([( 2 ,), ( 3 ,) ], names = [ "identifier" ] )
766+ expected_df .columns = pd .Index ([ 2 , 3 ], name = "identifier" )
733767 pd .testing .assert_frame_equal (expected_df , dps_list .to_pandas (include_aggregate_name = False ), check_freq = False )
734768
735769 def test_datapoints_list_names_dup (self ) -> None :
@@ -759,7 +793,7 @@ def test_datapoints_list_non_aligned(self) -> None:
759793 {1 : [1 , 2 , 3 , None , None ], 2 : [None , None , 3 , 4 , 5 ]},
760794 index = pd .to_datetime (range (1 , 6 ), unit = "ms" ),
761795 )
762- expected_df .columns = pd .MultiIndex . from_tuples ([( 1 ,), ( 2 ,) ], names = [ "identifier" ] )
796+ expected_df .columns = pd .Index ([ 1 , 2 ], name = "identifier" )
763797 pd .testing .assert_frame_equal (expected_df , dps_list .to_pandas (), check_freq = False )
764798
765799 def test_datapoints_list_empty (self ) -> None :
0 commit comments