Skip to content

Commit

Permalink
Feedback: assert length before slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Dec 9, 2024
1 parent d0d9221 commit 4bed059
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion metricflow/dataset/sql_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ def instances_for_time_dimensions(

def instance_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> TimeDimensionInstance:
"""Given the name of the time dimension, return the instance associated with it in the data set."""
return self.instances_for_time_dimensions((time_dimension_spec,))[0]
instances = self.instances_for_time_dimensions((time_dimension_spec,))
if not len(instances) == 1:
raise RuntimeError(
f"Unexpected number of time dimension instances found matching specs.\nSpecs: {time_dimension_spec}\n"
f"Instances: {instances}"
)
return instances[0]

def column_association_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> ColumnAssociation:
"""Given the name of the time dimension, return the set of columns associated with it in the data set."""
Expand Down

0 comments on commit 4bed059

Please sign in to comment.