datfid 0.1.16__py3-none-any.whl → 0.1.17__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.

Potentially problematic release.


This version of datfid might be problematic. Click here for more details.

datfid/client.py CHANGED
@@ -9,6 +9,35 @@ import gc
9
9
  import psutil
10
10
  import logging
11
11
 
12
+ # for nice output
13
+ class FitResult(SimpleNamespace):
14
+ _ROW4 = ["Estimate", "Standard Error", "T statistic", "P value"]
15
+ _PERF5 = ["R2 within", "R2 between", "R2 overall", "MSE", "MAE"]
16
+
17
+ @staticmethod
18
+ def _df4(rows_list):
19
+ if not isinstance(rows_list, list):
20
+ return rows_list
21
+ return pd.DataFrame(rows_list, index=FitResult._ROW4[:len(rows_list)])
22
+
23
+ @staticmethod
24
+ def _df_perf(rows_list):
25
+ if not isinstance(rows_list, list):
26
+ return rows_list
27
+ return pd.DataFrame(rows_list, index=FitResult._PERF5[:len(rows_list)])
28
+
29
+ def __init__(self, **kwargs):
30
+ # Convert list→DataFrame for table-like fields
31
+ if "alpha" in kwargs:
32
+ kwargs["alpha"] = self._df4(kwargs["alpha"])
33
+ if "beta" in kwargs:
34
+ kwargs["beta"] = self._df4(kwargs["beta"])
35
+ if "Performance" in kwargs:
36
+ kwargs["Performance"] = self._df_perf(kwargs["Performance"])
37
+ if "df" in kwargs and isinstance(kwargs["df"], list):
38
+ kwargs["df"] = pd.DataFrame(kwargs["df"])
39
+ super().__init__(**kwargs)
40
+
12
41
  class DATFIDClient:
13
42
  def __init__(self, token: str):
14
43
  self.api_url = "https://datfid-org-datfid-sdk.hf.space/"
@@ -54,7 +83,7 @@ class DATFIDClient:
54
83
  current_features: Optional[list] = None,
55
84
  filter_by_significance: bool = False,
56
85
  meanvar_test: bool = False
57
- ) -> SimpleNamespace:
86
+ ) -> FitResult:
58
87
  """
59
88
  Fit a model using the DATFID API.
60
89
 
@@ -99,8 +128,8 @@ class DATFIDClient:
99
128
  raise Exception(f"Model fit failed: {response.text}")
100
129
 
101
130
  result_dict = response.json()
102
- return SimpleNamespace(**result_dict)
103
-
131
+ return FitResult(**result_dict)
132
+
104
133
  def forecast_model(
105
134
  self,
106
135
  df_forecast: pd.DataFrame
@@ -156,7 +185,7 @@ class DATFIDClient:
156
185
  current_features: Optional[list] = None,
157
186
  filter_by_significance: bool = False,
158
187
  meanvar_test: bool = False
159
- ) -> Dict[str, SimpleNamespace]:
188
+ ) -> Dict[str, FitResult]:
160
189
  """
161
190
  Fit a model individual by individual using the DATFID API.
162
191
 
@@ -202,7 +231,7 @@ class DATFIDClient:
202
231
 
203
232
  raw = response.json() # { "<id>": { ... per-id result ... }, ... }
204
233
  # Wrap each per-id result into a SimpleNamespace for dot access:
205
- result_per_id = {str(k): SimpleNamespace(**v) for k, v in raw.items()}
234
+ result_per_id = {str(k): FitResult(**v) for k, v in raw.items()}
206
235
  return result_per_id # Dict[str, SimpleNamespace]
207
236
 
208
237
  def forecast_model_ind(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datfid
3
- Version: 0.1.16
3
+ Version: 0.1.17
4
4
  Summary: SDK to access the DATFID API hosted on Hugging Face Spaces
5
5
  Author: DATFID
6
6
  Author-email: igor.schapiro@datfid.com
@@ -0,0 +1,7 @@
1
+ datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
2
+ datfid/client.py,sha256=Nz5Up8cs5qjo2vKxap9NViRx0ukKXn8VTYoMVhUFf3o,9359
3
+ datfid-0.1.17.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
4
+ datfid-0.1.17.dist-info/METADATA,sha256=ISe-w7e3PLhAAbW3xZ2LhdktvdbMf7OESMmZPTR_30w,5146
5
+ datfid-0.1.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ datfid-0.1.17.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
7
+ datfid-0.1.17.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
2
- datfid/client.py,sha256=uza0OZBtm5aQF0xdFF2TIBUOYeQ9zYmX-hS8-OBXWqw,8267
3
- datfid-0.1.16.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
4
- datfid-0.1.16.dist-info/METADATA,sha256=frz6VkxxFwrNeY7-ZbN2U4H7nCwN3-DIH9WkEQyHJtU,5146
5
- datfid-0.1.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- datfid-0.1.16.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
7
- datfid-0.1.16.dist-info/RECORD,,