py2ls 0.1.8.3__py3-none-any.whl → 0.1.8.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py2ls/ips.py CHANGED
@@ -457,13 +457,15 @@ def str2date(date_str, fmt="%Y-%m-%d_%H:%M:%S"):
457
457
  # print(str2)
458
458
 
459
459
 
460
- def str2num(s, *args):
461
- delimiter = None
462
- round_digits = None
460
+ def str2num(s, *args, **kwargs):
461
+ delimiter = kwargs.get("sep", None)
462
+ round_digits = kwargs.get("round", None)
463
+ if delimiter is not None:
464
+ s = s.replace(delimiter, "")
463
465
  for arg in args:
464
- if isinstance(arg, str):
466
+ if isinstance(arg, str) and delimiter is None:
465
467
  delimiter = arg
466
- elif isinstance(arg, int):
468
+ elif isinstance(arg, int) and round_digits is None:
467
469
  round_digits = arg
468
470
  try:
469
471
  num = int(s)
@@ -491,17 +493,17 @@ def str2num(s, *args):
491
493
  "Multiple number segments found, cannot determine single numeric value"
492
494
  )
493
495
  except Exception as e:
494
- raise ValueError(f"Cannot convert {s} to a number: {e}")
496
+ return None
495
497
 
496
498
  # Apply rounding if specified
497
499
  if round_digits is not None:
498
500
  num_adj = num + 0.00000000001 # Ensure precise rounding
499
501
  num = round(num_adj, round_digits)
500
-
501
- # Apply delimiter formatting if specified
502
- if delimiter is not None:
503
- num_str = f"{num:,}".replace(",", delimiter)
504
- return num_str
502
+ if round_digits == 0:
503
+ num = int(num)
504
+ # if delimiter is not None:
505
+ # num_str = f"{num:,}".replace(",", delimiter)
506
+ # return num_str#s.replace(delimiter, "")
505
507
 
506
508
  return num
507
509
 
@@ -516,9 +518,9 @@ def str2num(s, *args):
516
518
  # print(str2num("12345.6789", " ", 2)) # Output: 12 345.68
517
519
  # print(str2num('111113.34555',3,',')) # Output: 111,113.346
518
520
  # print(str2num("123.55555 sec miniuets",3)) # Output: 1.3
519
- def num2str(num, *args):
520
- delimiter = None
521
- round_digits = None
521
+ def num2str(num, *args, **kwargs):
522
+ delimiter = kwargs.get("sep", None)
523
+ round_digits = kwargs.get("round", None)
522
524
 
523
525
  # Parse additional arguments
524
526
  for arg in args: