Skip to content

Commit 2f5a426

Browse files
committed
more updates to user None
1 parent e9387cc commit 2f5a426

File tree

3 files changed

+7
-34
lines changed

3 files changed

+7
-34
lines changed

lib/sycamore/sycamore/data/document.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,11 @@ def field_to_value(self, field: str) -> Any:
224224
Returns None if field does not exist in document.
225225
"""
226226
fields = field.split(".")
227-
if hasattr(self, fields[0]):
228-
value = getattr(self, fields[0])
229-
else:
230-
return None
227+
value = getattr(self, fields[0], None)
231228
if len(fields) > 1:
232-
assert fields[0] == "properties"
233229
for f in fields[1:]:
234-
if f in value:
235-
value = value[f]
230+
if isinstance(value, dict):
231+
value = value.get(f, None)
236232
else:
237233
return None
238234
return value

lib/sycamore/sycamore/query/execution/operations.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def make_filter_fn_join(field: str, join_set: set) -> Callable[[Document], bool]
363363
"""
364364

365365
def filter_fn_join(doc: Document) -> bool:
366-
value = str(doc.field_to_value(field))
366+
value = doc.field_to_value(field)
367367
return value in join_set
368368

369369
return filter_fn_join
@@ -391,7 +391,7 @@ def join_operation(docset1: DocSet, docset2: DocSet, field1: str, field2: str) -
391391
doc = Document.from_row(row)
392392
if isinstance(doc, MetadataDocument):
393393
continue
394-
value = str(doc.field_to_value(field1))
394+
value = doc.field_to_value(field1)
395395
unique_vals.add(value)
396396

397397
# filters docset2 based on matches of field2 with unique values
@@ -548,6 +548,8 @@ def ray_callable(input_dict: dict[str, Any]) -> dict[str, Any]:
548548

549549
if unique_field is not None:
550550
val = str(doc.field_to_value(unique_field))
551+
if val is None:
552+
return {"doc": None, "key": None, "unique": None}
551553
# updates row to include new col
552554
new_doc["unique"] = val
553555

lib/sycamore/sycamore/tests/unit/query/test_operations.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -348,31 +348,6 @@ def test_semantic_cluster(self, number_docset):
348348
elif doc.text_representation == "3" or doc.text_representation == "three":
349349
assert doc.properties["_autogen_ClusterAssignment"] == "group3"
350350

351-
# Helpers
352-
# def test_field_to_value(self):
353-
# doc = Document(
354-
# text_representation="hello",
355-
# doc_id=1,
356-
# properties={"letter": "A", "animal": "panda", "math": {"pi": 3.14, "e": 2.72, "tanx": "sinx/cosx"}},
357-
# )
358-
359-
# assert field_to_value(doc, "text_representation") == "hello"
360-
# assert field_to_value(doc, "doc_id") == 1
361-
# assert field_to_value(doc, "properties.letter") == "A"
362-
# assert field_to_value(doc, "properties.animal") == "panda"
363-
# assert field_to_value(doc, "properties.math.pi") == 3.14
364-
# assert field_to_value(doc, "properties.math.e") == 2.72
365-
# assert field_to_value(doc, "properties.math.tanx") == "sinx/cosx"
366-
367-
# with pytest.raises(KeyError):
368-
# field_to_value(doc, "properties.math.log")
369-
370-
# with pytest.raises(Exception):
371-
# field_to_value(doc, "document_id")
372-
373-
# with pytest.raises(AssertionError):
374-
# field_to_value(doc, "text_representation.text")
375-
376351
def test_convert_string_to_date(self):
377352
date_string = "2024-07-21"
378353
expected_date = datetime(2024, 7, 21)

0 commit comments

Comments
 (0)