15
15
import os
16
16
import tempfile
17
17
import unittest
18
+ import warnings
18
19
from datetime import datetime , timedelta
19
20
from typing import Any
20
21
@@ -208,39 +209,47 @@ def tearDown(self):
208
209
209
210
shutil .rmtree (self .data_dir )
210
211
211
- def test_empty_dataframe_raises_error (self ):
212
- """Test that completely empty dataframe raises ValueError """
212
+ def test_empty_dataframe_warns (self ):
213
+ """Test that completely empty dataframe warns """
213
214
empty_df = pd .DataFrame ()
214
215
215
- with self .assertRaises (ValueError ) as context :
216
+ with warnings .catch_warnings (record = True ) as warning_list :
217
+ warnings .simplefilter ("always" )
216
218
self .store .write_to_online_store (
217
219
feature_view_name = "driver_hourly_stats" , df = empty_df
218
220
)
219
221
220
- self .assertIn (
221
- "Cannot write empty dataframe to online store" , str (context .exception )
222
+ # Check that our specific warning message is present
223
+ warning_messages = [str (w .message ) for w in warning_list ]
224
+ self .assertTrue (
225
+ any ("Cannot write empty dataframe to online store" in msg for msg in warning_messages ),
226
+ f"Expected warning not found. Actual warnings: { warning_messages } "
222
227
)
223
228
224
- def test_empty_dataframe_async_raises_error (self ):
225
- """Test that completely empty dataframe raises ValueError in async version"""
229
+ def test_empty_dataframe_async_warns (self ):
230
+ """Test that completely empty dataframe warns instead of raising error in async version"""
226
231
import asyncio
227
232
228
233
async def test_async_empty ():
229
234
empty_df = pd .DataFrame ()
230
235
231
- with self .assertRaises (ValueError ) as context :
236
+ with warnings .catch_warnings (record = True ) as warning_list :
237
+ warnings .simplefilter ("always" )
232
238
await self .store .write_to_online_store_async (
233
239
feature_view_name = "driver_hourly_stats" , df = empty_df
234
240
)
235
241
236
- self .assertIn (
237
- "Cannot write empty dataframe to online store" , str (context .exception )
242
+ # Check that our specific warning message is present
243
+ warning_messages = [str (w .message ) for w in warning_list ]
244
+ self .assertTrue (
245
+ any ("Cannot write empty dataframe to online store" in msg for msg in warning_messages ),
246
+ f"Expected warning not found. Actual warnings: { warning_messages } "
238
247
)
239
248
240
249
asyncio .run (test_async_empty ())
241
250
242
- def test_dataframe_with_empty_feature_columns_raises_error (self ):
243
- """Test that dataframe with entity data but empty feature columns raises ValueError """
251
+ def test_dataframe_with_empty_feature_columns_warns (self ):
252
+ """Test that dataframe with entity data but empty feature columns warns instead of raising error """
244
253
current_time = pd .Timestamp .now ()
245
254
df_with_entity_only = pd .DataFrame (
246
255
{
@@ -253,18 +262,21 @@ def test_dataframe_with_empty_feature_columns_raises_error(self):
253
262
}
254
263
)
255
264
256
- with self .assertRaises (ValueError ) as context :
265
+ with warnings .catch_warnings (record = True ) as warning_list :
266
+ warnings .simplefilter ("always" )
257
267
self .store .write_to_online_store (
258
268
feature_view_name = "driver_hourly_stats" , df = df_with_entity_only
259
269
)
260
270
261
- self .assertIn (
262
- "Cannot write dataframe with empty feature columns to online store" ,
263
- str (context .exception ),
271
+ # Check that our specific warning message is present
272
+ warning_messages = [str (w .message ) for w in warning_list ]
273
+ self .assertTrue (
274
+ any ("Cannot write dataframe with empty feature columns to online store" in msg for msg in warning_messages ),
275
+ f"Expected warning not found. Actual warnings: { warning_messages } "
264
276
)
265
277
266
- def test_dataframe_with_empty_feature_columns_async_raises_error (self ):
267
- """Test that dataframe with entity data but empty feature columns raises ValueError in async version"""
278
+ def test_dataframe_with_empty_feature_columns_async_warns (self ):
279
+ """Test that dataframe with entity data but empty feature columns warns instead of raising error in async version"""
268
280
import asyncio
269
281
270
282
async def test_async_empty_features ():
@@ -280,14 +292,17 @@ async def test_async_empty_features():
280
292
}
281
293
)
282
294
283
- with self .assertRaises (ValueError ) as context :
295
+ with warnings .catch_warnings (record = True ) as warning_list :
296
+ warnings .simplefilter ("always" )
284
297
await self .store .write_to_online_store_async (
285
298
feature_view_name = "driver_hourly_stats" , df = df_with_entity_only
286
299
)
287
300
288
- self .assertIn (
289
- "Cannot write dataframe with empty feature columns to online store" ,
290
- str (context .exception ),
301
+ # Check that our specific warning message is present
302
+ warning_messages = [str (w .message ) for w in warning_list ]
303
+ self .assertTrue (
304
+ any ("Cannot write dataframe with empty feature columns to online store" in msg for msg in warning_messages ),
305
+ f"Expected warning not found. Actual warnings: { warning_messages } "
291
306
)
292
307
293
308
asyncio .run (test_async_empty_features ())
@@ -358,26 +373,30 @@ def test_mixed_dataframe_with_some_valid_features(self):
358
373
feature_view_name = "driver_hourly_stats" , df = mixed_df
359
374
)
360
375
361
- def test_empty_inputs_dict_raises_error (self ):
362
- """Test that empty inputs dict raises ValueError """
376
+ def test_empty_inputs_dict_warns (self ):
377
+ """Test that empty inputs dict warns instead of raising error """
363
378
empty_inputs = {
364
379
"driver_id" : [],
365
380
"conv_rate" : [],
366
381
"acc_rate" : [],
367
382
"avg_daily_trips" : [],
368
383
}
369
384
370
- with self .assertRaises (ValueError ) as context :
385
+ with warnings .catch_warnings (record = True ) as warning_list :
386
+ warnings .simplefilter ("always" )
371
387
self .store .write_to_online_store (
372
388
feature_view_name = "driver_hourly_stats" , inputs = empty_inputs
373
389
)
374
390
375
- self .assertIn (
376
- "Cannot write empty dataframe to online store" , str (context .exception )
377
- )
391
+ # Check that our specific warning message is present
392
+ warning_messages = [str (w .message ) for w in warning_list ]
393
+ self .assertTrue (
394
+ any ("Cannot write empty dataframe to online store" in msg for msg in warning_messages ),
395
+ f"Expected warning not found. Actual warnings: { warning_messages } "
396
+ )
378
397
379
- def test_inputs_dict_with_empty_features_raises_error (self ):
380
- """Test that inputs dict with empty feature values raises ValueError """
398
+ def test_inputs_dict_with_empty_features_warns (self ):
399
+ """Test that inputs dict with empty feature values warns instead of raising error """
381
400
current_time = pd .Timestamp .now ()
382
401
empty_feature_inputs = {
383
402
"driver_id" : [1001 , 1002 , 1003 ],
@@ -388,14 +407,16 @@ def test_inputs_dict_with_empty_features_raises_error(self):
388
407
"avg_daily_trips" : [None , None , None ],
389
408
}
390
409
391
- with self .assertRaises (ValueError ) as context :
410
+ with warnings .catch_warnings (record = True ) as warning_list :
411
+ warnings .simplefilter ("always" )
392
412
self .store .write_to_online_store (
393
413
feature_view_name = "driver_hourly_stats" , inputs = empty_feature_inputs
394
414
)
395
415
416
+ self .assertEqual (len (warning_list ), 1 )
396
417
self .assertIn (
397
418
"Cannot write dataframe with empty feature columns to online store" ,
398
- str (context . exception ),
419
+ str (warning_list [ 0 ]. message ),
399
420
)
400
421
401
422
0 commit comments