ratio1 3.4.124__py3-none-any.whl → 3.4.126__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.
ratio1/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "3.4.124"
1
+ __VER__ = "3.4.126"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
ratio1/bc/base.py CHANGED
@@ -92,51 +92,40 @@ class _SimpleJsonEncoder(json.JSONEncoder):
92
92
  return float(obj)
93
93
  elif isinstance(obj, np.ndarray):
94
94
  return obj.tolist()
95
- elif isinstance(obj, np.ndarray):
96
- return obj.tolist()
97
- elif isinstance(obj, datetime.datetime):
98
- return obj.strftime("%Y-%m-%d %H:%M:%S")
99
- else:
100
- return super(_SimpleJsonEncoder, self).default(obj)
101
-
102
- class _ComplexJsonEncoder(json.JSONEncoder):
103
- def default(self, obj):
104
- if isinstance(obj, np.integer):
105
- return int(obj)
106
- elif isinstance(obj, np.floating):
107
- return float(obj)
108
- elif isinstance(obj, np.ndarray):
109
- return obj.tolist()
95
+ # Datetime
110
96
  elif isinstance(obj, datetime.datetime):
111
97
  return obj.strftime("%Y-%m-%d %H:%M:%S")
112
- else:
113
- return super(_ComplexJsonEncoder, self).default(obj)
98
+ # torch
99
+ elif "torch" in str(type(obj)):
100
+ return str(obj)
101
+ # default
102
+ return super(_SimpleJsonEncoder, self).default(obj)
114
103
 
104
+ class _ComplexJsonEncoder(_SimpleJsonEncoder):
115
105
  def iterencode(self, o, _one_shot=False):
116
106
  """Encode the given object and yield each string representation as available."""
117
- if self.check_circular:
118
- markers = {}
119
- else:
120
- markers = None
121
- if self.ensure_ascii:
122
- _encoder = json.encoder.encode_basestring_ascii
123
- else:
124
- _encoder = json.encoder.encode_basestring
125
-
126
- def floatstr(o, allow_nan=self.allow_nan, _repr=float.__repr__, _inf=json.encoder.INFINITY, _neginf=-json.encoder.INFINITY):
127
- if o != o: # Check for NaN
128
- text = 'null'
129
- elif o == _inf:
130
- text = 'null'
131
- elif o == _neginf:
132
- text = 'null'
133
- else:
134
- return repr(o).rstrip('0').rstrip('.') if '.' in repr(o) else repr(o)
107
+ markers = {} if self.check_circular else None
108
+ _encoder = json.encoder.encode_basestring_ascii if self.ensure_ascii else json.encoder.encode_basestring
135
109
 
136
- if not allow_nan:
137
- raise ValueError("Out of range float values are not JSON compliant: " + repr(o))
138
-
139
- return text
110
+ def floatstr(
111
+ x, allow_nan=self.allow_nan, _repr=float.__repr__,
112
+ _inf=json.encoder.INFINITY, _neginf=-json.encoder.INFINITY
113
+ ):
114
+ # CRITICAL: normalize float subclasses (np.float64, etc.) to builtin float
115
+ # so we never emit "np.float64(9.99)" into JSON.
116
+ if type(x) is not float:
117
+ x = float(x)
118
+ # endif type check
119
+
120
+ # Check for NaN, Inf, -Inf
121
+ if x != x or x == _inf or x == _neginf:
122
+ if not allow_nan:
123
+ raise ValueError("Out of range float values are not JSON compliant: " + _repr(x))
124
+ return "null"
125
+
126
+ # Use builtin float repr (stable, JSON numeric literal)
127
+ return _repr(x)
128
+ # enddef floatstr
140
129
 
141
130
  # Convert indent to string if it's an integer (required for Python 3.13+)
142
131
  indent = self.indent
@@ -270,10 +270,18 @@ class _ComputerVisionMixin(object):
270
270
  plt.axis('off')
271
271
  fig = plt.gcf()
272
272
  fig.canvas.draw()
273
- data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
274
- w, h = fig.canvas.get_width_height()
275
273
  try:
276
- np_img = data.reshape((int(h), int(w), -1))
274
+ w, h = fig.canvas.get_width_height()
275
+ if hasattr(fig.canvas, 'tostring_rgb'):
276
+ data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
277
+ np_img = data.reshape((int(h), int(w), 3))
278
+ elif hasattr(fig.canvas, 'tostring_argb'):
279
+ data = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
280
+ argb = data.reshape((int(h), int(w), 4))
281
+ np_img = argb[:, :, 1:4]
282
+ else:
283
+ rgba = np.asarray(fig.canvas.buffer_rgba())
284
+ np_img = rgba[:, :, :3]
277
285
  except Exception as e:
278
286
  print(e)
279
287
  np_img = None
@@ -440,4 +448,4 @@ class _ComputerVisionMixin(object):
440
448
  resized = cv2.resize(image, dim, interpolation = inter)
441
449
 
442
450
  # return the resized image
443
- return resized
451
+ return resized
@@ -1,13 +1,10 @@
1
1
  import json
2
2
  import yaml
3
3
  import os
4
- import numpy as np
5
4
  import traceback
6
- import datetime
7
5
 
8
- from collections import OrderedDict
9
-
10
- from copy import deepcopy
6
+ from collections import OrderedDict
7
+ from ...bc.base import _ComplexJsonEncoder, _SimpleJsonEncoder, replace_nan_inf
11
8
 
12
9
  def copy_docstring(original):
13
10
  """
@@ -29,98 +26,15 @@ def copy_docstring(original):
29
26
  return decorator
30
27
 
31
28
 
32
- def replace_nan_inf(data, inplace=False):
33
- assert isinstance(data, (dict, list)), "Only dictionaries and lists are supported"
34
- if inplace:
35
- d = data
36
- else:
37
- d = deepcopy(data)
38
- stack = [d]
39
- while stack:
40
- current = stack.pop()
41
- for key, value in current.items():
42
- if isinstance(value, dict):
43
- stack.append(value)
44
- elif isinstance(value, list):
45
- for item in value:
46
- if isinstance(item, dict):
47
- stack.append(item)
48
- elif isinstance(value, float) and (np.isnan(value) or np.isinf(value)):
49
- current[key] = None
50
- return d
51
-
52
- class SimpleNPJson(json.JSONEncoder):
29
+ class SimpleNPJson(_SimpleJsonEncoder):
53
30
  """
54
31
  Used to help jsonify numpy arrays or lists that contain numpy data types,
55
32
  and handle datetime.
56
33
  """
57
- def default(self, obj):
58
- if isinstance(obj, np.integer):
59
- return int(obj)
60
- elif isinstance(obj, np.floating):
61
- return float(obj)
62
- elif isinstance(obj, np.ndarray):
63
- return obj.tolist()
64
- elif isinstance(obj, datetime.datetime):
65
- return obj.strftime("%Y-%m-%d %H:%M:%S")
66
- elif "torch" in str(type(obj)):
67
- return str(obj)
68
- else:
69
- return super(SimpleNPJson, self).default(obj)
70
-
71
- class NPJson(json.JSONEncoder):
72
- def default(self, obj):
73
- if isinstance(obj, np.integer):
74
- return int(obj)
75
- elif isinstance(obj, np.floating):
76
- return float(obj)
77
- elif isinstance(obj, np.ndarray):
78
- return obj.tolist()
79
- elif isinstance(obj, datetime.datetime):
80
- return obj.strftime("%Y-%m-%d %H:%M:%S")
81
- elif "torch" in str(type(obj)):
82
- return str(obj)
83
- else:
84
- return super(NPJson, self).default(obj)
85
-
86
- def iterencode(self, o, _one_shot=False):
87
- """Encode the given object and yield each string representation as available."""
88
- if self.check_circular:
89
- markers = {}
90
- else:
91
- markers = None
92
- if self.ensure_ascii:
93
- _encoder = json.encoder.encode_basestring_ascii
94
- else:
95
- _encoder = json.encoder.encode_basestring
96
-
97
- def floatstr(o, allow_nan=self.allow_nan, _repr=float.__repr__, _inf=json.encoder.INFINITY, _neginf=-json.encoder.INFINITY):
98
- if o != o: # Check for NaN
99
- text = 'null'
100
- elif o == _inf:
101
- text = 'null'
102
- elif o == _neginf:
103
- text = 'null'
104
- else:
105
- return repr(o).rstrip('0').rstrip('.') if '.' in repr(o) else repr(o)
106
-
107
- if not allow_nan:
108
- raise ValueError("Out of range float values are not JSON compliant: " + repr(o))
109
-
110
- return text
111
-
112
- # Convert indent to string if it's an integer (required for Python 3.13+)
113
- indent = self.indent
114
- if indent is not None and not isinstance(indent, str):
115
- indent = ' ' * indent
116
-
117
- _iterencode = json.encoder._make_iterencode(
118
- markers, self.default, _encoder, indent, floatstr,
119
- self.key_separator, self.item_separator, self.sort_keys,
120
- self.skipkeys, _one_shot
121
- )
122
- return _iterencode(o, 0)
34
+ pass
123
35
 
36
+ class NPJson(_ComplexJsonEncoder):
37
+ pass
124
38
 
125
39
  class _JSONSerializationMixin(object):
126
40
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ratio1
3
- Version: 3.4.124
3
+ Version: 3.4.126
4
4
  Summary: `ratio1` or Ration1 SDK is the Python SDK required for client app development for the Ratio1 ecosystem
5
5
  Project-URL: Homepage, https://github.com/Ratio1/ratio1_sdk
6
6
  Project-URL: Bug Tracker, https://github.com/Ratio1/ratio1_sdk/issues
@@ -1,5 +1,5 @@
1
1
  ratio1/__init__.py,sha256=YimqgDbjLuywsf8zCWE0EaUXH4MBUrqLxt0TDV558hQ,632
2
- ratio1/_ver.py,sha256=V3wM9ENgD5iKWU_u3Dv1dX0N64XQgIwz2-AUegpOMeU,332
2
+ ratio1/_ver.py,sha256=WYlO2MZRg2pVclGXnijRTllaAOkXr7doUQiRB9lTCDY,332
3
3
  ratio1/base_decentra_object.py,sha256=iXvAAf6wPnGWzeeiRfwLojVoan-m1e_VsyPzjUQuENo,4492
4
4
  ratio1/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  ratio1/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
@@ -14,7 +14,7 @@ ratio1/base/webapp_pipeline.py,sha256=H83EjkmyljetdHZ18V5R8OU3wXoWi_EpV0AAhQ4AM6
14
14
  ratio1/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
15
15
  ratio1/base/payload/payload.py,sha256=MoCeL6iZzl1an-4eqRpLW0iz6Yk3OvlBrymcmhWeecM,2689
16
16
  ratio1/bc/__init__.py,sha256=BI5pcqHdhwnMdbWTYDLW1cVP_844VtLra-lz7xprgsk,171
17
- ratio1/bc/base.py,sha256=sqiGjsskpD4L9Tb53mHdrla9DL85PsfJS8ah7kR_63c,46477
17
+ ratio1/bc/base.py,sha256=LU75I3ef-yzlke30YPP94lHWw8AaCPqUz185jIL3AnQ,46254
18
18
  ratio1/bc/chain.py,sha256=HCTQGnmuKqTvUo95OKdg8rL2jhKfSMwrich2e_7Nyms,2336
19
19
  ratio1/bc/ec.py,sha256=FwlkWmJvQ9aHuf_BZX1CWSUAxw6OZ9jBparLIWcs_e4,18933
20
20
  ratio1/bc/evm.py,sha256=iMLdm_rtQFqmt44zTE_UA0OKSTmuH7sCSI2iKvFI1_k,52013
@@ -87,11 +87,11 @@ ratio1/logging/base_logger.py,sha256=iwNirMP38xEA26K8arwDjHXOjJhjE5q_SHzipjqAQzo
87
87
  ratio1/logging/small_logger.py,sha256=BoCCEDManhe804zqfykZAvXUu9gV0_2NPebftUMIyPk,2998
88
88
  ratio1/logging/logger_mixins/__init__.py,sha256=fmDmGVDV41Dfoafe0yCZxJ_CqxWac4DSM8hO6UZnrcA,641
89
89
  ratio1/logging/logger_mixins/class_instance_mixin.py,sha256=x2vr_VrRAzGhjgayPxV9t3XtU-c0VoHZb6cjDbslJM8,2725
90
- ratio1/logging/logger_mixins/computer_vision_mixin.py,sha256=TrtG7ayM2ab-4jjIkIWAQaFi9cVfiINAWrJCt8mCCFI,13213
90
+ ratio1/logging/logger_mixins/computer_vision_mixin.py,sha256=9IccYDZFnBNEUutymvEdhmStPrhK-XT-B55x7g-sRH8,13567
91
91
  ratio1/logging/logger_mixins/datetime_mixin.py,sha256=ORqOW4bxaI0UKLtII8-QhOiHvIfwNfz1irBrdYsOJFA,11264
92
92
  ratio1/logging/logger_mixins/download_mixin.py,sha256=ZZ1QuQ7kDcUkxhu65odD2pvBRlogsb8mvEEViIYV_L0,18668
93
93
  ratio1/logging/logger_mixins/general_serialization_mixin.py,sha256=bNM-6AsYhKD56v79hvJDgO8un5rHH4IKv1XJ3yksseQ,7424
94
- ratio1/logging/logger_mixins/json_serialization_mixin.py,sha256=Xs_3zufgP7HLwBBWYOdcvd5b__clY3dG7Bc1RshJN4c,15407
94
+ ratio1/logging/logger_mixins/json_serialization_mixin.py,sha256=GFtk3oDd0rstq0au2QthOkxhUWBHctt4WyDLRKQ-TBo,12729
95
95
  ratio1/logging/logger_mixins/machine_mixin.py,sha256=BOk7nHThRG6nNVK8atM5TrBfuHuaeLwb2sheLvE357o,3985
96
96
  ratio1/logging/logger_mixins/pickle_serialization_mixin.py,sha256=tmdmoRz38iJGfK4J37oEghbRizN4BdZs7F2kObZ2ldQ,11391
97
97
  ratio1/logging/logger_mixins/process_mixin.py,sha256=eI0izBAhStPOant2SZv2ZuTDH10s2ON_CkuGQEEFew4,1888
@@ -109,8 +109,8 @@ ratio1/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,10
109
109
  ratio1/utils/config.py,sha256=Elfkl7W4aDMvB5WZLiYlPXrecBncgTxb4hcKhQedMzI,10111
110
110
  ratio1/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
111
111
  ratio1/utils/oracle_sync/oracle_tester.py,sha256=aJOPcZhtbw1XPqsFG4qYpfv2Taj5-qRXbwJzrPyeXDE,27465
112
- ratio1-3.4.124.dist-info/METADATA,sha256=KX9h9ghSAVUrTYsK5BQ6rOjtyRLpvMc34YLa_OdIIWs,12256
113
- ratio1-3.4.124.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
114
- ratio1-3.4.124.dist-info/entry_points.txt,sha256=DR_olREzU1egwmgek3s4GfQslBi-KR7lXsd4ap0TFxE,46
115
- ratio1-3.4.124.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
116
- ratio1-3.4.124.dist-info/RECORD,,
112
+ ratio1-3.4.126.dist-info/METADATA,sha256=t3oQHfvAkdt0kMhcB3SRpPH4C69QYaO2hlNKzRgFVxw,12256
113
+ ratio1-3.4.126.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
114
+ ratio1-3.4.126.dist-info/entry_points.txt,sha256=DR_olREzU1egwmgek3s4GfQslBi-KR7lXsd4ap0TFxE,46
115
+ ratio1-3.4.126.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
116
+ ratio1-3.4.126.dist-info/RECORD,,