Skip to content

Commit 8ffae3c

Browse files
committed
clean up
1 parent 3a9e5c5 commit 8ffae3c

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/pandas_openscm/index_manipulation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,9 @@ def set_levels(
728728
Input MultiIndex
729729
730730
levels_to_set
731-
Mapping of level names to values to set
731+
Mapping of level names to values to set. If values is of type `Collection`,
732+
it must be of the same length as the MultiIndex. If it is not a `Collection`,
733+
it will be set to the same value for all levels.
732734
733735
Returns
734736
-------
@@ -742,13 +744,15 @@ def set_levels(
742744
ValueError
743745
If the length of the values is not equal to the length of the index
744746
"""
747+
# TODO mypy says this is unreachable
745748
if not isinstance(ini, pd.MultiIndex):
746749
msg = f"Expected MultiIndex, got {type(ini)}"
747750
raise TypeError(msg)
748751

749752
df = ini.to_frame(index=False)
750753

751754
for level, value in levels_to_set.items():
755+
# TODO do we need the isinstance check for strings here?
752756
if isinstance(value, Collection) and not isinstance(value, str):
753757
if len(value) != len(ini):
754758
msg = (

tests/integration/index_manipulation/test_integration_index_manipulation_set_levels.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ def test_set_levels_with_a_dataframe():
159159

160160

161161
def test_set_levels_raises_type_error():
162-
"""
163-
Test that set_levels raises an error when the levels to set are not in the index.
164-
"""
165162
start = pd.Index(range(10), name="index")
166163

167164
levels_to_set = {"new_variable": "test"}
@@ -171,10 +168,6 @@ def test_set_levels_raises_type_error():
171168

172169

173170
def test_set_levels_raises_value_error():
174-
"""
175-
Test that set_levels raises an error when the levels to set are same length
176-
as index.
177-
"""
178171
start = pd.MultiIndex.from_tuples(
179172
[
180173
("sa", "va", "kg", 0),

0 commit comments

Comments
 (0)