@@ -492,3 +492,44 @@ def test_alt_data_infill_restricting_date_range(self) -> None:
492492 )
493493 expected_df = self .df .with_columns (pl .Series ("values" , [1.0 , 20.0 , 3.0 , None , 5.0 ]))
494494 assert_frame_equal (result_df , expected_df , check_column_order = False )
495+
496+ def test_alt_data_infill_with_alt_data_provided (self ) -> None :
497+ """Test infilling from a provided alternative DataFrame."""
498+ alt_df = pl .DataFrame (
499+ {
500+ "timestamp" : self .df ["timestamp" ],
501+ "alt_values_df" : [11.0 , 22.0 , 33.0 , 44.0 , 55.0 ],
502+ }
503+ )
504+ infiller = AltData (alt_data_column = "alt_values_df" , alt_df = alt_df )
505+ result_df = infiller .apply (self .tf .df , self .tf .time_name , self .tf .periodicity , "values" )
506+ expected_df = self .df .with_columns (pl .Series ("values" , [1.0 , 22.0 , 3.0 , 44.0 , 5.0 ]))
507+ assert_frame_equal (result_df , expected_df , check_column_order = False )
508+
509+ def test_alt_data_infill_with_alt_data_missing_time_column (self ) -> None :
510+ """Test error when provided alt_data is missing the time column."""
511+ alt_df = pl .DataFrame ({"alt_values_df" : [11.0 , 22.0 , 33.0 , 44.0 , 55.0 ]})
512+ infiller = AltData (alt_data_column = "alt_values" , alt_df = alt_df )
513+ with self .assertRaises (ColumnNotFoundError ):
514+ infiller .apply (self .tf .df , self .tf .time_name , self .tf .periodicity , "values" )
515+
516+ def test_alt_data_infill_with_alt_data_missing_data_column (self ) -> None :
517+ """Test error when provided alt_data is missing the data column."""
518+ alt_df = pl .DataFrame ({"time" : self .df ["timestamp" ]})
519+ infiller = AltData (alt_data_column = "non_existent_column" , alt_df = alt_df )
520+ with self .assertRaises (ColumnNotFoundError ):
521+ infiller .apply (self .tf .df , self .tf .time_name , self .tf .periodicity , "values" )
522+
523+ def test_alt_data_infill_with_alt_data_and_column_in_main_df (self ) -> None :
524+ """Test that alt_data is prioritized when column name exists in main df."""
525+ alt_df = pl .DataFrame (
526+ {
527+ "timestamp" : self .df ["timestamp" ],
528+ "alt_values" : [11.0 , 22.0 , 33.0 , 44.0 , 55.0 ],
529+ }
530+ )
531+ infiller = AltData (alt_data_column = "alt_values" , alt_df = alt_df )
532+
533+ with self .assertRaises (ValueError ):
534+ infiller .apply (self .tf .df , self .tf .time_name , self .tf .periodicity , "values" )
535+
0 commit comments