@@ -653,7 +653,32 @@ def test_fix_non_consistent_historical_data_no_change(self):
653653 )
654654 self .assertEqual (expected , view .to_dict ())
655655
656- def test_fix_non_consistent_historical_data_mixed_values (self ):
656+ def test_fix_non_consistent_historical_data_mixed_values1 (self ):
657+ df = pandas .DataFrame (
658+ [
659+ dict (date = "2025/01/01" , time_p = 0.51 , exporter = "E1" , model_s = "O" , model = "M" ),
660+ dict (date = "2025/01/02" , time_p = 0.51 , exporter = "E1" , model_s = "O" , model = "M" ),
661+ dict (date = "2025/01/03" , time_p = 0.53 , exporter = "E1" , model_s = "A" , model = "M" ),
662+ ]
663+ )
664+ cube = CubeLogs (
665+ df , keys = ["^model*" , "exporter" , "opt" ], values = ["time_p" ], time = "date"
666+ ).load ()
667+ view , _view_def = cube .view (
668+ CubeViewDef (["^model.*" ], ["^time_.*" ], fix_aggregation_change = ["model_s" ]),
669+ return_view_def = True ,
670+ )
671+ raw = view .to_dict ()
672+ self .assertEqual (
673+ {
674+ ("time_p" , pandas .Timestamp ("2025-01-01 00:00:00" )): {"A-O" : 0.51 },
675+ ("time_p" , pandas .Timestamp ("2025-01-02 00:00:00" )): {"A-O" : 0.51 },
676+ ("time_p" , pandas .Timestamp ("2025-01-03 00:00:00" )): {"A-O" : 0.53 },
677+ },
678+ raw ,
679+ )
680+
681+ def test_fix_non_consistent_historical_data_mixed_values2 (self ):
657682 df = pandas .DataFrame (
658683 [
659684 dict (date = "2025/01/01" , time_p = 0.51 , exporter = "E1" , model_s = "O" , model = "M" ),
@@ -703,6 +728,37 @@ def test_fix_non_consistent_historical_data_mixed_nan(self):
703728 raw ,
704729 )
705730
731+ def test_fix_non_consistent_historical_data_nan (self ):
732+ df = pandas .DataFrame (
733+ [
734+ dict (date = "2025/01/01" , time_p = 0.51 , exporter = "E1" , model_s = "O" , model = "M" ),
735+ dict (date = "2025/01/02" , time_p = 0.51 , exporter = "E1" , model_s = "O" , model = "M" ),
736+ dict (date = "2025/01/03" , time_p = 0.53 , exporter = "E1" , model_s = "A" , model = "M" ),
737+ dict (date = "2025/01/01" , time_p = 0.51 , exporter = "E2" , model = "M" ),
738+ dict (date = "2025/01/02" , time_p = 0.51 , exporter = "E2" , model = "M" ),
739+ dict (date = "2025/01/03" , time_p = 0.53 , exporter = "E2" , model = "M" ),
740+ ]
741+ )
742+ cube = CubeLogs (
743+ df , keys = ["^model*" , "exporter" , "opt" ], values = ["time_p" ], time = "date"
744+ ).load ()
745+ view , _view_def = cube .view (
746+ CubeViewDef (["^model.*" ], ["^time_.*" ], fix_aggregation_change = ["model_s" ]),
747+ return_view_def = True ,
748+ )
749+ raw = view .reset_index (drop = True ).fillna ("NAN" ).to_dict (orient = "list" )
750+ self .assertEqual (
751+ {
752+ ("time_p" , "E1" , pandas .Timestamp ("2025-01-01 00:00:00" )): ["NAN" , 0.51 ],
753+ ("time_p" , "E1" , pandas .Timestamp ("2025-01-02 00:00:00" )): ["NAN" , 0.51 ],
754+ ("time_p" , "E1" , pandas .Timestamp ("2025-01-03 00:00:00" )): ["NAN" , 0.53 ],
755+ ("time_p" , "E2" , pandas .Timestamp ("2025-01-01 00:00:00" )): [0.51 , "NAN" ],
756+ ("time_p" , "E2" , pandas .Timestamp ("2025-01-02 00:00:00" )): [0.51 , "NAN" ],
757+ ("time_p" , "E2" , pandas .Timestamp ("2025-01-03 00:00:00" )): [0.53 , "NAN" ],
758+ },
759+ raw ,
760+ )
761+
706762
707763if __name__ == "__main__" :
708764 unittest .main (verbosity = 2 )
0 commit comments