Rename timer; add a test for OutputContext.
[python_utils.git] / string_utils.py
index 7ad9c42a1e2af3304e18ba6beba021c35acbb086..911008d4c93bc50d6d78bb7d09d9d4aaaffdbcd5 100644 (file)
@@ -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)