From 33c36494c50c199746bee33b71e8d54f8fede4b6 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 16 Dec 2023 13:50:37 +0800 Subject: [PATCH] Refactor the kwargs_to_strings decorator to avoid try-except in loops --- pygmt/helpers/decorators.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 4e3d6926671..2db184efada 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -757,15 +757,12 @@ def new_module(*args, **kwargs): else: continue - issequence = fmt in separators - if issequence and is_nonstr_iter(value): + if fmt in separators and is_nonstr_iter(value): for index, item in enumerate(value): - try: + if " " in str(item): # Check if there is a space " " when converting # a pandas.Timestamp/xr.DataArray to a string. # If so, use np.datetime_as_string instead. - assert " " not in str(item) - except AssertionError: # Convert datetime-like item to ISO 8601 # string format like YYYY-MM-DDThh:mm:ss.ffffff. value[index] = np.datetime_as_string(