Skip to content

Commit 1f7f979

Browse files
aniketpaluntkathole
authored andcommitted
Edited test cases to check for warnings, minor code changed
Signed-off-by: Aniket Paluskar <[email protected]>
1 parent d6f4b4e commit 1f7f979

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

sdk/python/feast/feature_store.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,7 @@ def write_to_online_store(
19011901
if df is not None:
19021902
if df.empty:
19031903
warnings.warn("Cannot write empty dataframe to online store")
1904+
return # Early return for empty dataframe
19041905

19051906
# Check if feature columns are empty (entity columns may have data but feature columns are empty)
19061907
feature_column_names = [f.name for f in feature_view.features]
@@ -1910,6 +1911,7 @@ def write_to_online_store(
19101911
warnings.warn(
19111912
"Cannot write dataframe with empty feature columns to online store"
19121913
)
1914+
return # Early return for empty feature columns
19131915

19141916
provider = self._get_provider()
19151917
provider.ingest_df(feature_view, df)
@@ -1945,6 +1947,7 @@ async def write_to_online_store_async(
19451947
if df is not None:
19461948
if df.empty:
19471949
warnings.warn("Cannot write empty dataframe to online store")
1950+
return # Early return for empty dataframe
19481951

19491952
# Check if feature columns are empty (entity columns may have data but feature columns are empty)
19501953
feature_column_names = [f.name for f in feature_view.features]
@@ -1954,6 +1957,7 @@ async def write_to_online_store_async(
19541957
warnings.warn(
19551958
"Cannot write dataframe with empty feature columns to online store"
19561959
)
1960+
return # Early return for empty feature columns
19571961

19581962
provider = self._get_provider()
19591963
await provider.ingest_df_async(feature_view, df)

sdk/python/tests/unit/online_store/test_online_writes.py

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import tempfile
1717
import unittest
18+
import warnings
1819
from datetime import datetime, timedelta
1920
from typing import Any
2021

@@ -208,39 +209,47 @@ def tearDown(self):
208209

209210
shutil.rmtree(self.data_dir)
210211

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"""
213214
empty_df = pd.DataFrame()
214215

215-
with self.assertRaises(ValueError) as context:
216+
with warnings.catch_warnings(record=True) as warning_list:
217+
warnings.simplefilter("always")
216218
self.store.write_to_online_store(
217219
feature_view_name="driver_hourly_stats", df=empty_df
218220
)
219221

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}"
222227
)
223228

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"""
226231
import asyncio
227232

228233
async def test_async_empty():
229234
empty_df = pd.DataFrame()
230235

231-
with self.assertRaises(ValueError) as context:
236+
with warnings.catch_warnings(record=True) as warning_list:
237+
warnings.simplefilter("always")
232238
await self.store.write_to_online_store_async(
233239
feature_view_name="driver_hourly_stats", df=empty_df
234240
)
235241

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}"
238247
)
239248

240249
asyncio.run(test_async_empty())
241250

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"""
244253
current_time = pd.Timestamp.now()
245254
df_with_entity_only = pd.DataFrame(
246255
{
@@ -253,18 +262,21 @@ def test_dataframe_with_empty_feature_columns_raises_error(self):
253262
}
254263
)
255264

256-
with self.assertRaises(ValueError) as context:
265+
with warnings.catch_warnings(record=True) as warning_list:
266+
warnings.simplefilter("always")
257267
self.store.write_to_online_store(
258268
feature_view_name="driver_hourly_stats", df=df_with_entity_only
259269
)
260270

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}"
264276
)
265277

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"""
268280
import asyncio
269281

270282
async def test_async_empty_features():
@@ -280,14 +292,17 @@ async def test_async_empty_features():
280292
}
281293
)
282294

283-
with self.assertRaises(ValueError) as context:
295+
with warnings.catch_warnings(record=True) as warning_list:
296+
warnings.simplefilter("always")
284297
await self.store.write_to_online_store_async(
285298
feature_view_name="driver_hourly_stats", df=df_with_entity_only
286299
)
287300

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}"
291306
)
292307

293308
asyncio.run(test_async_empty_features())
@@ -358,26 +373,30 @@ def test_mixed_dataframe_with_some_valid_features(self):
358373
feature_view_name="driver_hourly_stats", df=mixed_df
359374
)
360375

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"""
363378
empty_inputs = {
364379
"driver_id": [],
365380
"conv_rate": [],
366381
"acc_rate": [],
367382
"avg_daily_trips": [],
368383
}
369384

370-
with self.assertRaises(ValueError) as context:
385+
with warnings.catch_warnings(record=True) as warning_list:
386+
warnings.simplefilter("always")
371387
self.store.write_to_online_store(
372388
feature_view_name="driver_hourly_stats", inputs=empty_inputs
373389
)
374390

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+
)
378397

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"""
381400
current_time = pd.Timestamp.now()
382401
empty_feature_inputs = {
383402
"driver_id": [1001, 1002, 1003],
@@ -388,14 +407,16 @@ def test_inputs_dict_with_empty_features_raises_error(self):
388407
"avg_daily_trips": [None, None, None],
389408
}
390409

391-
with self.assertRaises(ValueError) as context:
410+
with warnings.catch_warnings(record=True) as warning_list:
411+
warnings.simplefilter("always")
392412
self.store.write_to_online_store(
393413
feature_view_name="driver_hourly_stats", inputs=empty_feature_inputs
394414
)
395415

416+
self.assertEqual(len(warning_list), 1)
396417
self.assertIn(
397418
"Cannot write dataframe with empty feature columns to online store",
398-
str(context.exception),
419+
str(warning_list[0].message),
399420
)
400421

401422

0 commit comments

Comments
 (0)