X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=string_utils.py;h=911008d4c93bc50d6d78bb7d09d9d4aaaffdbcd5;hb=0e451d3b3bf899b3d9ac0c38e3c3cd9d9be170ba;hp=7ad9c42a1e2af3304e18ba6beba021c35acbb086;hpb=3bc4daf1edc121cd633429187392227f2fa61885;p=python_utils.git diff --git a/string_utils.py b/string_utils.py index 7ad9c42..911008d 100644 --- a/string_utils.py +++ b/string_utils.py @@ -11,9 +11,6 @@ from typing import Any, List, Optional import unicodedata from uuid import uuid4 -import dateparse.dateparse_utils as dp - - logger = logging.getLogger(__name__) NUMBER_RE = re.compile(r"^([+\-]?)((\d+)(\.\d+)?([e|E]\d+)?|\.\d+)$") @@ -228,10 +225,14 @@ def strip_escape_sequences(in_str: str) -> str: return in_str -def add_thousands_separator(in_str: str, *, separator_char = ',', places = 3) -> str: +def add_thousands_separator( + in_str: str, + *, + separator_char = ',', + places = 3 +) -> str: if isinstance(in_str, int): in_str = f'{in_str}' - if is_number(in_str): return _add_thousands_separator( in_str, @@ -815,6 +816,7 @@ def to_bool(in_str: str) -> bool: def to_date(in_str: str) -> Optional[datetime.date]: + import dateparse.dateparse_utils as dp try: d = dp.DateParser() d.parse(in_str) @@ -825,6 +827,7 @@ def to_date(in_str: str) -> Optional[datetime.date]: def valid_date(in_str: str) -> bool: + import dateparse.dateparse_utils as dp try: d = dp.DateParser() _ = d.parse(in_str) @@ -835,6 +838,7 @@ def valid_date(in_str: str) -> bool: def to_datetime(in_str: str) -> Optional[datetime.datetime]: + import dateparse.dateparse_utils as dp try: d = dp.DateParser() dt = d.parse(in_str)