@@ -175,13 +175,9 @@ def setUp(self):
175175 start_date = end_date - timedelta (days = 1 )
176176
177177 driver_entities = [1001 ]
178- driver_df = create_driver_hourly_stats_df (
179- driver_entities , start_date , end_date
180- )
178+ driver_df = create_driver_hourly_stats_df (driver_entities , start_date , end_date )
181179 driver_stats_path = os .path .join (self .data_dir , "driver_stats.parquet" )
182- driver_df .to_parquet (
183- path = driver_stats_path , allow_truncated_timestamps = True
184- )
180+ driver_df .to_parquet (path = driver_stats_path , allow_truncated_timestamps = True )
185181
186182 driver = Entity (name = "driver" , join_keys = ["driver_id" ])
187183
@@ -209,90 +205,107 @@ def setUp(self):
209205
210206 def tearDown (self ):
211207 import shutil
208+
212209 shutil .rmtree (self .data_dir )
213210
214211 def test_empty_dataframe_raises_error (self ):
215212 """Test that completely empty dataframe raises ValueError"""
216213 empty_df = pd .DataFrame ()
217-
214+
218215 with self .assertRaises (ValueError ) as context :
219216 self .store .write_to_online_store (
220217 feature_view_name = "driver_hourly_stats" , df = empty_df
221218 )
222-
223- self .assertIn ("Cannot write empty dataframe to online store" , str (context .exception ))
219+
220+ self .assertIn (
221+ "Cannot write empty dataframe to online store" , str (context .exception )
222+ )
224223
225224 def test_empty_dataframe_async_raises_error (self ):
226225 """Test that completely empty dataframe raises ValueError in async version"""
227226 import asyncio
228-
227+
229228 async def test_async_empty ():
230229 empty_df = pd .DataFrame ()
231-
230+
232231 with self .assertRaises (ValueError ) as context :
233232 await self .store .write_to_online_store_async (
234233 feature_view_name = "driver_hourly_stats" , df = empty_df
235234 )
236-
237- self .assertIn ("Cannot write empty dataframe to online store" , str (context .exception ))
238-
235+
236+ self .assertIn (
237+ "Cannot write empty dataframe to online store" , str (context .exception )
238+ )
239+
239240 asyncio .run (test_async_empty ())
240241
241242 def test_dataframe_with_empty_feature_columns_raises_error (self ):
242243 """Test that dataframe with entity data but empty feature columns raises ValueError"""
243244 current_time = pd .Timestamp .now ()
244- df_with_entity_only = pd .DataFrame ({
245- "driver_id" : [1001 , 1002 , 1003 ],
246- "event_timestamp" : [current_time ] * 3 ,
247- "created" : [current_time ] * 3 ,
248- "conv_rate" : [None , None , None ], # All nulls
249- "acc_rate" : [None , None , None ], # All nulls
250- "avg_daily_trips" : [None , None , None ] # All nulls
251- })
252-
245+ df_with_entity_only = pd .DataFrame (
246+ {
247+ "driver_id" : [1001 , 1002 , 1003 ],
248+ "event_timestamp" : [current_time ] * 3 ,
249+ "created" : [current_time ] * 3 ,
250+ "conv_rate" : [None , None , None ], # All nulls
251+ "acc_rate" : [None , None , None ], # All nulls
252+ "avg_daily_trips" : [None , None , None ], # All nulls
253+ }
254+ )
255+
253256 with self .assertRaises (ValueError ) as context :
254257 self .store .write_to_online_store (
255258 feature_view_name = "driver_hourly_stats" , df = df_with_entity_only
256259 )
257-
258- self .assertIn ("Cannot write dataframe with empty feature columns to online store" , str (context .exception ))
260+
261+ self .assertIn (
262+ "Cannot write dataframe with empty feature columns to online store" ,
263+ str (context .exception ),
264+ )
259265
260266 def test_dataframe_with_empty_feature_columns_async_raises_error (self ):
261267 """Test that dataframe with entity data but empty feature columns raises ValueError in async version"""
262268 import asyncio
263-
269+
264270 async def test_async_empty_features ():
265271 current_time = pd .Timestamp .now ()
266- df_with_entity_only = pd .DataFrame ({
267- "driver_id" : [1001 , 1002 , 1003 ],
268- "event_timestamp" : [current_time ] * 3 ,
269- "created" : [current_time ] * 3 ,
270- "conv_rate" : [None , None , None ],
271- "acc_rate" : [None , None , None ],
272- "avg_daily_trips" : [None , None , None ]
273- })
274-
272+ df_with_entity_only = pd .DataFrame (
273+ {
274+ "driver_id" : [1001 , 1002 , 1003 ],
275+ "event_timestamp" : [current_time ] * 3 ,
276+ "created" : [current_time ] * 3 ,
277+ "conv_rate" : [None , None , None ],
278+ "acc_rate" : [None , None , None ],
279+ "avg_daily_trips" : [None , None , None ],
280+ }
281+ )
282+
275283 with self .assertRaises (ValueError ) as context :
276284 await self .store .write_to_online_store_async (
277285 feature_view_name = "driver_hourly_stats" , df = df_with_entity_only
278286 )
279-
280- self .assertIn ("Cannot write dataframe with empty feature columns to online store" , str (context .exception ))
281-
287+
288+ self .assertIn (
289+ "Cannot write dataframe with empty feature columns to online store" ,
290+ str (context .exception ),
291+ )
292+
282293 asyncio .run (test_async_empty_features ())
283294
284295 def test_valid_dataframe (self ):
285296 """Test that valid dataframe with feature data succeeds"""
286297 current_time = pd .Timestamp .now ()
287- valid_df = pd .DataFrame ({
288- "driver_id" : [1001 , 1002 ],
289- "event_timestamp" : [current_time ] * 2 ,
290- "created" : [current_time ] * 2 ,
291- "conv_rate" : [0.5 , 0.7 ],
292- "acc_rate" : [0.8 , 0.9 ],
293- "avg_daily_trips" : [10 , 12 ]
294- })
295-
298+ valid_df = pd .DataFrame (
299+ {
300+ "driver_id" : [1001 , 1002 ],
301+ "event_timestamp" : [current_time ] * 2 ,
302+ "created" : [current_time ] * 2 ,
303+ "conv_rate" : [0.5 , 0.7 ],
304+ "acc_rate" : [0.8 , 0.9 ],
305+ "avg_daily_trips" : [10 , 12 ],
306+ }
307+ )
308+
296309 # This should not raise an exception
297310 self .store .write_to_online_store (
298311 feature_view_name = "driver_hourly_stats" , df = valid_df
@@ -301,40 +314,45 @@ def test_valid_dataframe(self):
301314 def test_valid_dataframe_async (self ):
302315 """Test that valid dataframe with feature data succeeds in async version"""
303316 import asyncio
317+
304318 import pytest
305-
319+
306320 pytest .skip ("Feature not implemented yet" )
307-
321+
308322 async def test_async_valid ():
309323 current_time = pd .Timestamp .now ()
310- valid_df = pd .DataFrame ({
311- "driver_id" : [1001 , 1002 ],
312- "event_timestamp" : [current_time ] * 2 ,
313- "created" : [current_time ] * 2 ,
314- "conv_rate" : [0.5 , 0.7 ],
315- "acc_rate" : [0.8 , 0.9 ],
316- "avg_daily_trips" : [10 , 12 ]
317- })
318-
324+ valid_df = pd .DataFrame (
325+ {
326+ "driver_id" : [1001 , 1002 ],
327+ "event_timestamp" : [current_time ] * 2 ,
328+ "created" : [current_time ] * 2 ,
329+ "conv_rate" : [0.5 , 0.7 ],
330+ "acc_rate" : [0.8 , 0.9 ],
331+ "avg_daily_trips" : [10 , 12 ],
332+ }
333+ )
334+
319335 # This should not raise an exception
320336 await self .store .write_to_online_store_async (
321337 feature_view_name = "driver_hourly_stats" , df = valid_df
322338 )
323-
339+
324340 asyncio .run (test_async_valid ())
325341
326342 def test_mixed_dataframe_with_some_valid_features (self ):
327343 """Test that dataframe with some valid feature values succeeds"""
328344 current_time = pd .Timestamp .now ()
329- mixed_df = pd .DataFrame ({
330- "driver_id" : [1001 , 1002 , 1003 ],
331- "event_timestamp" : [current_time ] * 3 ,
332- "created" : [current_time ] * 3 ,
333- "conv_rate" : [0.5 , None , 0.7 ], # Mixed values
334- "acc_rate" : [0.8 , 0.9 , None ], # Mixed values
335- "avg_daily_trips" : [10 , 12 , 15 ] # All valid
336- })
337-
345+ mixed_df = pd .DataFrame (
346+ {
347+ "driver_id" : [1001 , 1002 , 1003 ],
348+ "event_timestamp" : [current_time ] * 3 ,
349+ "created" : [current_time ] * 3 ,
350+ "conv_rate" : [0.5 , None , 0.7 ], # Mixed values
351+ "acc_rate" : [0.8 , 0.9 , None ], # Mixed values
352+ "avg_daily_trips" : [10 , 12 , 15 ], # All valid
353+ }
354+ )
355+
338356 # This should not raise an exception because not all feature values are null
339357 self .store .write_to_online_store (
340358 feature_view_name = "driver_hourly_stats" , df = mixed_df
@@ -346,15 +364,17 @@ def test_empty_inputs_dict_raises_error(self):
346364 "driver_id" : [],
347365 "conv_rate" : [],
348366 "acc_rate" : [],
349- "avg_daily_trips" : []
367+ "avg_daily_trips" : [],
350368 }
351-
369+
352370 with self .assertRaises (ValueError ) as context :
353371 self .store .write_to_online_store (
354372 feature_view_name = "driver_hourly_stats" , inputs = empty_inputs
355373 )
356-
357- self .assertIn ("Cannot write empty dataframe to online store" , str (context .exception ))
374+
375+ self .assertIn (
376+ "Cannot write empty dataframe to online store" , str (context .exception )
377+ )
358378
359379 def test_inputs_dict_with_empty_features_raises_error (self ):
360380 """Test that inputs dict with empty feature values raises ValueError"""
@@ -365,15 +385,18 @@ def test_inputs_dict_with_empty_features_raises_error(self):
365385 "created" : [current_time ] * 3 ,
366386 "conv_rate" : [None , None , None ],
367387 "acc_rate" : [None , None , None ],
368- "avg_daily_trips" : [None , None , None ]
388+ "avg_daily_trips" : [None , None , None ],
369389 }
370-
390+
371391 with self .assertRaises (ValueError ) as context :
372392 self .store .write_to_online_store (
373393 feature_view_name = "driver_hourly_stats" , inputs = empty_feature_inputs
374394 )
375-
376- self .assertIn ("Cannot write dataframe with empty feature columns to online store" , str (context .exception ))
395+
396+ self .assertIn (
397+ "Cannot write dataframe with empty feature columns to online store" ,
398+ str (context .exception ),
399+ )
377400
378401
379402class TestOnlineWritesWithTransform (unittest .TestCase ):
0 commit comments