Skip to content

Commit

Permalink
remove (assert_)is_single_datapoint methods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
livhe committed Sep 7, 2023
1 parent e2aa0bc commit 10810c4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
25 changes: 0 additions & 25 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,31 +413,6 @@ def test_assert_is_single_error(self):

assert "test_name" in str(e)

def test_is_single_datapoint(self):
index = _create_valid_index(
{"patient_1": {"a": ["test_1"], "b": ["1"]}}, columns_names=["patients", "tests", "extra with space"]
)
ds = Dataset(subset_index=index)
assert ds.is_single_datapoint() is True
assert ds.groupby(["patients"]).is_single_datapoint() is True
assert ds.groupby(["patients", "tests"]).is_single_datapoint() is True

@pytest.mark.parametrize(
"groupby_cols", (None, "tests", ["patients", "tests"], ["patients", "tests", "extra with space"])
)
def test_assert_is_single_datapoint_error(self, groupby_cols):
index = _create_valid_index(
{
"patient_1": {"a": ["test_1"], "b": ["0", "1"]},
"patient_2": {"a": ["test_1"], "b": ["0", "1"]},
},
columns_names=["patients", "tests", "extra with space"],
)
ds = Dataset(subset_index=index, groupby_cols=groupby_cols)
with pytest.raises(ValueError) as e:
ds.assert_is_single_datapoint("test_datapoint_name")
assert "test_datapoint_name" in str(e)

def test_create_index_call(self):
with pytest.raises(NotImplementedError):
_ = Dataset().index
Expand Down
25 changes: 0 additions & 25 deletions tpcp/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,31 +370,6 @@ def assert_is_single(self, groupby_cols: Optional[Union[str, List[str]]], proper
f"is only a single combination of the columns {groupby_cols} left in a data subset,"
)

def is_single_datapoint(self) -> bool:
"""Return True if index contains only one row.
This is independent of the groupby settings.
This means it is equivalent to `is_single_group` if no grouping is given.
"""
return self.is_single(None)

def assert_is_single_datapoint(self, property_name) -> None:
"""Raise error if index does contain more than one row.
Parameters
----------
property_name
Name of the property this check is used in.
Used to format the error message.
"""
if not self.is_single_datapoint():
raise ValueError(
f"The attribute `{property_name}` of dataset {self.__class__.__name__} can only be accessed if there "
f"is only a single row (i.e. single datapoint) left in the data subset index independent of the groupby"
f"level."
)

def assert_is_single_group(self, property_name) -> None:
"""Raise error if index does contain more than one group/row.
Expand Down

0 comments on commit 10810c4

Please sign in to comment.