Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding * selection of schema #1197

Merged
merged 1 commit into from
Jul 11, 2023
Merged
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
3 changes: 3 additions & 0 deletions merlin/models/torch/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ def select_schema(schema: Schema, selection: Selection) -> Schema:
elif isinstance(selection, (Tags, TagSet)):
selected = schema.select_by_tag(selection)
elif isinstance(selection, str):
if selection == "*":
return schema

selected = Schema([schema[selection]])
elif isinstance(selection, (list, tuple)):
if all(isinstance(s, str) for s in selection):
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/torch/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def test_select_column(self):
output_2 = select(self.schema, ColumnSchema("user_id"))
assert output == output_2 == Schema([column])

def test_select_star(self):
output = select(self.schema, "*")
assert output == self.schema

def test_exceptions(self):
with pytest.raises(ValueError, match="is not valid"):
select(self.schema, 1)
Expand Down