dcicutils 8.13.3.1b26__tar.gz → 8.13.3.1b29__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/PKG-INFO +1 -1
  2. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/misc_utils.py +75 -41
  3. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/pyproject.toml +1 -1
  4. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/LICENSE.txt +0 -0
  5. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/README.rst +0 -0
  6. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/__init__.py +0 -0
  7. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/base.py +0 -0
  8. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/beanstalk_utils.py +0 -0
  9. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/bundle_utils.py +0 -0
  10. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/captured_output.py +0 -0
  11. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/cloudformation_utils.py +0 -0
  12. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/codebuild_utils.py +0 -0
  13. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/command_utils.py +0 -0
  14. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/common.py +0 -0
  15. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/contribution_scripts.py +0 -0
  16. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/contribution_utils.py +0 -0
  17. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/creds_utils.py +0 -0
  18. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/data_readers.py +0 -0
  19. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/data_utils.py +0 -0
  20. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/datetime_utils.py +0 -0
  21. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/deployment_utils.py +0 -0
  22. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/diff_utils.py +0 -0
  23. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/docker_utils.py +0 -0
  24. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/ecr_scripts.py +0 -0
  25. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/ecr_utils.py +0 -0
  26. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/ecs_utils.py +0 -0
  27. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/env_base.py +0 -0
  28. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/env_manager.py +0 -0
  29. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/env_scripts.py +0 -0
  30. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/env_utils.py +0 -0
  31. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/env_utils_legacy.py +0 -0
  32. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/es_utils.py +0 -0
  33. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/exceptions.py +0 -0
  34. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/ff_mocks.py +0 -0
  35. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/ff_utils.py +0 -0
  36. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/file_utils.py +0 -0
  37. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/function_cache_decorator.py +0 -0
  38. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/glacier_utils.py +0 -0
  39. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/hack_for_elasticsearch_numpy_usage.py +0 -0
  40. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/http_utils.py +0 -0
  41. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/jh_utils.py +0 -0
  42. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/kibana/dashboards.json +0 -0
  43. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/kibana/readme.md +0 -0
  44. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/lang_utils.py +0 -0
  45. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_policies/c4-infrastructure.jsonc +0 -0
  46. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_policies/c4-python-infrastructure.jsonc +0 -0
  47. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_policies/park-lab-common-server.jsonc +0 -0
  48. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_policies/park-lab-common.jsonc +0 -0
  49. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_policies/park-lab-gpl-pipeline.jsonc +0 -0
  50. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_policies/park-lab-pipeline.jsonc +0 -0
  51. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/license_utils.py +0 -0
  52. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/log_utils.py +0 -0
  53. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/obfuscation_utils.py +0 -0
  54. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/opensearch_utils.py +0 -0
  55. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/portal_object_utils.py +0 -0
  56. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/portal_utils.py +0 -0
  57. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/progress_bar.py +0 -0
  58. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/project_utils.py +0 -0
  59. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/qa_checkers.py +0 -0
  60. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/qa_utils.py +0 -0
  61. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/redis_tools.py +0 -0
  62. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/redis_utils.py +0 -0
  63. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/s3_utils.py +0 -0
  64. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/schema_utils.py +0 -0
  65. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/scripts/publish_to_pypi.py +0 -0
  66. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/scripts/run_license_checker.py +0 -0
  67. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/scripts/update_portal_object.py +0 -0
  68. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/scripts/view_portal_object.py +0 -0
  69. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/secrets_utils.py +0 -0
  70. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/sheet_utils.py +0 -0
  71. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/snapshot_utils.py +0 -0
  72. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/ssl_certificate_utils.py +0 -0
  73. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/structured_data.py +0 -0
  74. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/submitr/progress_constants.py +0 -0
  75. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/submitr/ref_lookup_strategy.py +0 -0
  76. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/task_utils.py +0 -0
  77. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/tmpfile_utils.py +0 -0
  78. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/trace_utils.py +0 -0
  79. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/validation_utils.py +0 -0
  80. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/variant_utils.py +0 -0
  81. {dcicutils-8.13.3.1b26 → dcicutils-8.13.3.1b29}/dcicutils/zip_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.13.3.1b26
3
+ Version: 8.13.3.1b29
4
4
  Summary: Utility package for interacting with the 4DN Data Portal and other 4DN resources
5
5
  Home-page: https://github.com/4dn-dcic/utils
6
6
  License: MIT
@@ -990,6 +990,10 @@ def to_integer(value: str,
990
990
  allow_commas: bool = False,
991
991
  allow_multiplier_suffix: bool = False,
992
992
  fallback: Optional[Union[int, float]] = None) -> Optional[int]:
993
+ """
994
+ Converts the given string value to an int or None or the given fallback value if malformed.
995
+ See comments in to_number for details on the other arguments.
996
+ """
993
997
  return to_number(value, fallback=fallback, as_float=False,
994
998
  allow_commas=allow_commas,
995
999
  allow_multiplier_suffix=allow_multiplier_suffix)
@@ -999,25 +1003,33 @@ def to_float(value: str,
999
1003
  allow_commas: bool = False,
1000
1004
  allow_multiplier_suffix: bool = False,
1001
1005
  fallback: Optional[Union[int, float]] = None) -> Optional[int]:
1006
+ """
1007
+ Converts the given string value to a float or None or the given fallback value if malformed.
1008
+ See comments in to_number for details on the other arguments.
1009
+ """
1002
1010
  return to_number(value, fallback=fallback, as_float=True,
1003
1011
  allow_commas=allow_commas,
1004
1012
  allow_multiplier_suffix=allow_multiplier_suffix)
1005
1013
 
1006
1014
 
1007
- _TO_NUMBER_MULTIPLIER_K = 1000
1008
- _TO_NUMBER_MULTIPLIER_M = 1000 * _TO_NUMBER_MULTIPLIER_K
1009
- _TO_NUMBER_MULTIPLIER_G = 1000 * _TO_NUMBER_MULTIPLIER_M
1010
- _TO_NUMBER_MULTIPLIER_T = 1000 * _TO_NUMBER_MULTIPLIER_G
1015
+ _TO_NUMBER_POWER_OF_TEN_FOR_NOTHING = 0
1016
+ _TO_NUMBER_POWER_OF_TEN_FOR_K = 3
1017
+ _TO_NUMBER_POWER_OF_TEN_FOR_M = 6
1018
+ _TO_NUMBER_POWER_OF_TEN_FOR_G = 9
1019
+ _TO_NUMBER_POWER_OF_TEN_FOR_T = 12
1011
1020
 
1012
1021
  _TO_NUMBER_MULTIPLIER_SUFFIXES = {
1013
- "K": _TO_NUMBER_MULTIPLIER_K,
1014
- "KB": _TO_NUMBER_MULTIPLIER_K,
1015
- "M": _TO_NUMBER_MULTIPLIER_M,
1016
- "MB": _TO_NUMBER_MULTIPLIER_M,
1017
- "G": _TO_NUMBER_MULTIPLIER_G,
1018
- "GB": _TO_NUMBER_MULTIPLIER_G,
1019
- "T": _TO_NUMBER_MULTIPLIER_T,
1020
- "TB": _TO_NUMBER_MULTIPLIER_T
1022
+ "K": _TO_NUMBER_POWER_OF_TEN_FOR_K,
1023
+ "KB": _TO_NUMBER_POWER_OF_TEN_FOR_K,
1024
+ "M": _TO_NUMBER_POWER_OF_TEN_FOR_M,
1025
+ "MB": _TO_NUMBER_POWER_OF_TEN_FOR_M,
1026
+ "G": _TO_NUMBER_POWER_OF_TEN_FOR_G,
1027
+ "GB": _TO_NUMBER_POWER_OF_TEN_FOR_G,
1028
+ "T": _TO_NUMBER_POWER_OF_TEN_FOR_T,
1029
+ "TB": _TO_NUMBER_POWER_OF_TEN_FOR_T,
1030
+ # B means bytes or bases and BP means base pairs; needs to be last.
1031
+ "B": _TO_NUMBER_POWER_OF_TEN_FOR_NOTHING,
1032
+ "BP": _TO_NUMBER_POWER_OF_TEN_FOR_NOTHING
1021
1033
  }
1022
1034
 
1023
1035
 
@@ -1027,24 +1039,32 @@ def to_number(value: str,
1027
1039
  allow_multiplier_suffix: bool = False,
1028
1040
  fallback: Optional[Union[int, float]] = None) -> Optional[Union[int, float]]:
1029
1041
  """
1030
- Converts the given string value to an int, or float if as_float is True, or None if malformed.
1031
- If allow_commas is True then allow commas (only) every three digits. If allow_multiplier_suffix
1032
- is True allow any of K, KB; or M, MB; or G, or GB; or T, TB (case-insensitive), to mean multiply
1033
- value by one thousand; one million; one billion; or one trillion; respectively. If as_float is True
1034
- then value is parsed and returned as a float rather than int. Note that even if as_float is False,
1035
- values that might look like a float, can be an int, for example, "1.5K", returns 1500 as an int;
1036
- but "1.5002K" returns None, i.e. since 1.5002K is 1500.2 which is not an int.
1042
+ Converts the given string value to an int, or float if as_float is True,
1043
+ or None or the given fallback value if malformed.
1044
+
1045
+ If allow_commas is True then allows appropriately placed commas (i.e. every three digits).
1046
+
1047
+ If allow_multiplier_suffix is True allows any of the multiplier suffixes K, KB; M, MB;
1048
+ or G, GB; or T, TB; all case-insensitive; which will multiply the value by a thousand;
1049
+ a million; a billion; or a trillion; respectively.
1050
+
1051
+ If as_float is True then value is parsed and returned as a float rather than int.
1052
+
1053
+ Note that even if as_float is False, values that might LOOK like a float, can be
1054
+ an int, for example, "1.5K", returns 1500 as an int since it is; but "1.5002K"
1055
+ is malformed, since 1.5002K is equivalent to 1500.2 which is not an int.
1037
1056
  """
1038
1057
 
1039
1058
  if not (isinstance(value, str) and (value := value.strip())):
1059
+ # Just in case the value is already the actual/desired return type.
1040
1060
  if as_float is True:
1041
1061
  return float(value) if isinstance(value, (float, int)) else fallback
1042
1062
  else:
1043
1063
  return value if isinstance(value, int) else fallback
1044
1064
 
1045
- value_multiplier = 1
1046
- value_negative = False
1065
+ value_multiplier = _TO_NUMBER_POWER_OF_TEN_FOR_NOTHING
1047
1066
  value_fraction = None
1067
+ value_negative = False
1048
1068
 
1049
1069
  if value.startswith("-"):
1050
1070
  if not (value := value[1:].strip()):
@@ -1058,28 +1078,27 @@ def to_number(value: str,
1058
1078
  value_upper = value.upper()
1059
1079
  for suffix in _TO_NUMBER_MULTIPLIER_SUFFIXES:
1060
1080
  if value_upper.endswith(suffix):
1061
- value_multiplier *= _TO_NUMBER_MULTIPLIER_SUFFIXES[suffix]
1081
+ value_multiplier = _TO_NUMBER_MULTIPLIER_SUFFIXES[suffix]
1062
1082
  if not (value := value[:-len(suffix)].strip()):
1063
1083
  return fallback
1064
1084
  break
1065
1085
 
1066
1086
  if (allow_multiplier_suffix is True) or (as_float is True):
1067
- # Allow for example "1.5K" to mean 1500 (integer).
1087
+ # Allow for example "1.5K" to mean 1500 (int).
1068
1088
  if (dot_index := value.rfind(".")) >= 0:
1069
1089
  if value_fraction := value[dot_index + 1:].strip():
1070
- try:
1071
- value_fraction = float(f"0.{value_fraction}")
1072
- except Exception:
1090
+ if not value_fraction.isdigit():
1073
1091
  return fallback
1074
1092
  if not (value := value[:dot_index].strip()):
1075
1093
  if not value_fraction:
1076
1094
  return fallback
1077
1095
  value = "0"
1078
1096
  elif (as_float is not True) and (value_dot_zero_suffix := re.search(r"\.0*$", value)):
1079
- # Allow for example "123.00" to mean 123 (integer).
1097
+ # Allow for example "123.00" to mean 123 (int).
1080
1098
  value = value[:value_dot_zero_suffix.start()]
1081
1099
 
1082
1100
  if (allow_commas is True) and ("," in value):
1101
+ # Make sure any commas are properly placed/spaced.
1083
1102
  if not re.fullmatch(r"(-?\d{1,3}(,\d{3})*)", value):
1084
1103
  return fallback
1085
1104
  value = value.replace(",", "")
@@ -1087,23 +1106,38 @@ def to_number(value: str,
1087
1106
  if not value.isdigit():
1088
1107
  return fallback
1089
1108
 
1090
- value = float(value) if as_float is True else int(value)
1091
-
1092
- if value_fraction:
1093
- value_float = (float(value) + value_fraction) * float(value_multiplier)
1094
- if as_float is True:
1095
- value = value_float
1109
+ if value_multiplier != _TO_NUMBER_POWER_OF_TEN_FOR_NOTHING:
1110
+ # We do string manipulation for the (power of ten) multiplier and NOT normal multiplicative
1111
+ # arithmetic because this can EASILY yield UNEXPECTED floating point related INACCURACIES.
1112
+ # E.g. to_integer("1.5678K", allow_multiplier_suffix=True) would yield 1567.8000000000002
1113
+ # rather than 1567.8 if (we simply did 1.5678 * 1000.0); also tried multiplying by 10 at
1114
+ # a time, and using Decimal, which obviated some, but not all, of the idiosyncrasies.
1115
+ if value_fraction:
1116
+ for _ in range(value_multiplier):
1117
+ if value_fraction:
1118
+ value += value_fraction[0]
1119
+ value_fraction = value_fraction[1:]
1120
+ else:
1121
+ value += "0"
1122
+ if value_fraction:
1123
+ if as_float is not True:
1124
+ # Left over fraction for int with multiplier, e.g. "1.2345K" -> 1234.5.
1125
+ return fallback
1126
+ value = float(f"{value}.{value_fraction}")
1127
+ else:
1128
+ value = float(value) if as_float else int(value)
1129
+ else:
1130
+ value = value + ("0" * value_multiplier)
1131
+ value = float(value) if as_float else int(value)
1132
+ elif as_float is True:
1133
+ if value_fraction:
1134
+ value = float(f"{value}.{value_fraction}")
1096
1135
  else:
1097
- value = int(value_float)
1098
- if value_float != value:
1099
- return fallback
1136
+ value = float(value)
1100
1137
  else:
1101
- value *= value_multiplier
1138
+ value = int(value)
1102
1139
 
1103
- if value_negative:
1104
- value = -value
1105
-
1106
- return value
1140
+ return -value if value_negative else value
1107
1141
 
1108
1142
 
1109
1143
  def to_boolean(value: str, fallback: Optional[Any]) -> Optional[Any]:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dcicutils"
3
- version = "8.13.3.1b26" # TODO: To become 8.14.0
3
+ version = "8.13.3.1b29" # TODO: To become 8.14.0
4
4
  description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
5
5
  authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
6
6
  license = "MIT"