Skip to content

Commit 28e3cf3

Browse files
authored
Refactor the kwargs_to_strings decorator to avoid try-except in loops (#2885)
1 parent 25914d8 commit 28e3cf3

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

pygmt/helpers/decorators.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,15 +757,12 @@ def new_module(*args, **kwargs):
757757
else:
758758
continue
759759

760-
issequence = fmt in separators
761-
if issequence and is_nonstr_iter(value):
760+
if fmt in separators and is_nonstr_iter(value):
762761
for index, item in enumerate(value):
763-
try:
762+
if " " in str(item):
764763
# Check if there is a space " " when converting
765764
# a pandas.Timestamp/xr.DataArray to a string.
766765
# If so, use np.datetime_as_string instead.
767-
assert " " not in str(item)
768-
except AssertionError:
769766
# Convert datetime-like item to ISO 8601
770767
# string format like YYYY-MM-DDThh:mm:ss.ffffff.
771768
value[index] = np.datetime_as_string(

0 commit comments

Comments
 (0)