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

Make _parse_size robust to already parsed values #142

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0.7.0
~~~~~
- StepColormap: inclusive lower bound (@MxMartin #141)
- Add color schemes: plasma, inferno, magma (@FlorinAndrei #131)
- StepColormap: inclusive lower bound (@MxMartin #141)
- Add color schemes: plasma, inferno, magma (@FlorinAndrei #131)
- Allow branca ColorMap in write_png (@Conengmo #126)
- More flexible _parse_size (@Conengmo #125)

Expand Down
7 changes: 7 additions & 0 deletions branca/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ def _parse_size(value):
raise ValueError(
f"Cannot parse {value!r}, it should be a number followed by a unit.",
)
elif (
isinstance(value, tuple)
and isinstance(value[0], (int, float))
and isinstance(value[1], str)
):
# value had been already parsed
return value
else:
raise TypeError(
f"Cannot parse {value!r}, it should be a number or a string containing a number and a unit.",
Expand Down