Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lamindb/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def parse_nested_brackets(dtype_str: str) -> dict[str, Any]:
# No brackets - handle simple cases like "A" or "A.field"
if "." in dtype_str:
parts = dtype_str.split(".")
if len(parts) == 2 and parts[1][0].isupper():
if len(parts) == 2 and parts[1] != "" and parts[1][0].isupper():
# bionty.CellType
return {"registry": dtype_str, "filter_str": "", "field": ""}
elif len(parts) == 3:
Expand Down
14 changes: 14 additions & 0 deletions tests/core/test_feature_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lamindb.models.feature import (
parse_dtype,
parse_filter_string,
parse_nested_brackets,
resolve_relation_filters,
serialize_dtype,
)
Expand Down Expand Up @@ -123,6 +124,19 @@ def test_serialize_with_field_information():
# -----------------------------------------------------------------------------


def test_parse_nested_brackets_trailing_dot():
# a trailing dot used to raise `IndexError: string index out of range`
# because `parts[1][0]` was accessed on an empty second part
assert parse_nested_brackets("bionty.") == {
"registry": "bionty",
"filter_str": "",
"field": "",
}
# malformed dtype must surface as a clear ValidationError, not IndexError
with pytest.raises(ValidationError):
parse_dtype("cat[bionty.]")


def test_simple_record_with_subtype_and_field():
# Create a Record type to get its UID
customer_type = ln.Record(name="Customer", is_type=True).save()
Expand Down