@@ -34,7 +34,8 @@ def test_merge_informative_pair():
3434 assert "volume_1h" in result .columns
3535 assert result ["volume" ].equals (data ["volume" ])
3636
37- # First 3 rows are empty
37+ # First 3 rows are empty.
38+ # Pre-fillup doesn't happen as there is no prior candlw in the informative dataframe
3839 assert result .iloc [0 ]["date_1h" ] is pd .NaT
3940 assert result .iloc [1 ]["date_1h" ] is pd .NaT
4041 assert result .iloc [2 ]["date_1h" ] is pd .NaT
@@ -109,13 +110,37 @@ def test_merge_informative_pair_monthly():
109110 # Candle is empty, as the start-date did fail.
110111 candle3 = result .loc [(result ["date" ] == "2022-11-30T22:00:00.000Z" )]
111112 assert candle3 .iloc [0 ]["date" ] == pd .Timestamp ("2022-11-30T22:00:00.000Z" )
112- assert candle3 .iloc [0 ]["date_1M" ] is pd .NaT
113+ # Merged on prior month
114+ assert candle3 .iloc [0 ]["date_1M" ] == pd .Timestamp ("2022-10-01T00:00:00.000Z" )
113115
114116 # First candle with 1M data merged.
115117 candle4 = result .loc [(result ["date" ] == "2022-11-30T23:00:00.000Z" )]
116118 assert candle4 .iloc [0 ]["date" ] == pd .Timestamp ("2022-11-30T23:00:00.000Z" )
117119 assert candle4 .iloc [0 ]["date_1M" ] == pd .Timestamp ("2022-11-01T00:00:00.000Z" )
118120
121+ # Very first candle in the result dataframe
122+ # Merged the latest informative candle before the start-date
123+ candle5 = result .iloc [0 ]
124+ assert candle5 ["date" ] == pd .Timestamp ("2022-11-28T00:00:00.000Z" )
125+ assert candle5 ["date_1M" ] == pd .Timestamp ("2022-10-01T00:00:00.000Z" )
126+
127+
128+ def test_merge_informative_pair_no_overlap ():
129+ # Covers roughly a day
130+ data = generate_test_data ("1m" , 1440 , "2022-11-28" )
131+ # Data stops WAY before the main data starts
132+ informative = generate_test_data ("1h" , 40 , "2022-11-01" )
133+
134+ result = merge_informative_pair (data , informative , "1m" , "1h" , ffill = True )
135+
136+ assert isinstance (result , pd .DataFrame )
137+ assert len (result ) == len (data )
138+ assert "date" in result .columns
139+ assert result ["date" ].equals (data ["date" ])
140+ assert "date_1h" in result .columns
141+ # If there's no overlap, forward filling should not fill anything
142+ assert result ["date_1h" ].isnull ().all ()
143+
119144
120145def test_merge_informative_pair_same ():
121146 data = generate_test_data ("15m" , 40 )
0 commit comments