Skip to content

Commit

Permalink
Remove unused function.
Browse files Browse the repository at this point in the history
This function is not used. Its functionality is implemented elsewhere.
  • Loading branch information
ioannis-vm committed May 18, 2024
1 parent a15fbc8 commit 29461bc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 79 deletions.
52 changes: 0 additions & 52 deletions pelicun/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,58 +1071,6 @@ def with_parsed_str_na_values(df: pd.DataFrame) -> pd.DataFrame:
)


def process_loc(string, stories):
"""
Parses the 'location' parameter from input to determine the
specific locations to be processed. This function interprets
various string formats to output a list of integers representing
locations.
Parameters
----------
string : str
A string that describes the location or range of locations of
the asset. It can be a single number, a range (e.g., '3-7'),
'all', 'top', 'roof', or 'last'.
stories : int
The total number of locations in the asset, used to interpret
relative terms like 'top' or 'roof', or to generate a range
for 'all'.
Returns
-------
list of int or None
A list of integers representing each floor specified by the
string. Returns None if the string does not conform to
expected formats.
Raises
------
ValueError
Raises an exception if the string contains a range that is not
interpretable (e.g., non-integer values or logical
inconsistencies in the range).
"""
try:
res = int(string)
return [
res,
]
except ValueError as exc:
if "-" in string:
s_low, s_high = string.split('-')
s_low = process_loc(s_low, stories)
s_high = process_loc(s_high, stories)
return list(range(s_low[0], s_high[0] + 1))
if string == "all":
return list(range(1, stories + 1))
if string in {"top", "roof", "last"}:
return [
stories,
]
raise ValueError(f'Invalid string: {string}') from exc


def dedupe_index(dataframe, dtype=str):
"""
Modifies the index of a DataFrame to ensure all index elements are
Expand Down
27 changes: 0 additions & 27 deletions pelicun/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,33 +602,6 @@ def test_with_parsed_str_na_values():
)


def test_process_loc():
# Test when string can be converted to an int
assert base.process_loc('5', 10) == [
5,
]

# Test when string is in the form 'low-high'
assert base.process_loc('2-5', 10) == [2, 3, 4, 5]

# Test when string is 'all'
assert base.process_loc('all', 10) == list(range(1, 11))

# Test when string is 'top'
assert base.process_loc('top', 10) == [
10,
]

# Test when string is 'roof'
assert base.process_loc('roof', 10) == [
10,
]

# Test when string cannot be converted to an int or recognized
with pytest.raises(ValueError):
base.process_loc('abc', 10)


def test_run_input_specs():
assert os.path.basename(base.pelicun_path) == 'pelicun'

Expand Down

0 comments on commit 29461bc

Please sign in to comment.