datfid 0.1.13__tar.gz → 0.1.15__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datfid
3
- Version: 0.1.13
3
+ Version: 0.1.15
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
@@ -144,3 +144,105 @@ class DATFIDClient:
144
144
  except Exception as e:
145
145
  self.logger.error(f"Forecast generation failed: {str(e)}")
146
146
  raise
147
+
148
+ def fit_model_ind(
149
+ self,
150
+ df: pd.DataFrame,
151
+ id_col: str,
152
+ time_col: str,
153
+ y: str,
154
+ lag_y: Optional[Union[int, str, list[int]]] = None,
155
+ lagged_features: Optional[Dict[str, int]] = None,
156
+ current_features: Optional[list] = None,
157
+ filter_by_significance: bool = False,
158
+ meanvar_test: bool = False
159
+ ) -> SimpleNamespace:
160
+ """
161
+ Fit a model individual by individual using the DATFID API.
162
+
163
+ Args:
164
+ df: DataFrame containing the data
165
+ id_col: Name of the ID column
166
+ time_col: Name of the time column
167
+ y: Name of the target variable
168
+ lagged_features: Dictionary of features and their lag values
169
+ current_features: List of current features to use
170
+ filter_by_significance: Whether to filter features by significance
171
+ meanvar_test: Whether to perform mean-variance test
172
+
173
+ Returns:
174
+ SimpleNamespace containing the model fit results
175
+ """
176
+
177
+ df = df.copy()
178
+ for col in df.columns:
179
+ if pd.api.types.is_datetime64_any_dtype(df[col]):
180
+ df[col] = df[col].astype(str)
181
+
182
+ data = {
183
+ "df": df.to_dict(orient="records"),
184
+ "id_col": id_col,
185
+ "time_col": time_col,
186
+ "y": y,
187
+ "lag_y": lag_y,
188
+ "lagged_features": lagged_features or {},
189
+ "current_features": current_features or [],
190
+ "filter_by_significance": filter_by_significance,
191
+ "meanvar_test": meanvar_test
192
+ }
193
+
194
+ response = requests.post(
195
+ f"{self.api_url}modelfit_ind/",
196
+ json=data,
197
+ headers=self.headers
198
+ )
199
+
200
+ if response.status_code != 200:
201
+ raise Exception(f"Model fit failed: {response.text}")
202
+
203
+ result_dict = response.json()
204
+ return SimpleNamespace(**result_dict)
205
+
206
+ def forecast_model_ind(
207
+ self,
208
+ df_forecast: pd.DataFrame
209
+ ) -> pd.DataFrame:
210
+ """
211
+ Generate forecasts using the fitted individual by individual model.
212
+
213
+ Args:
214
+ df_forecast: DataFrame containing the forecast data
215
+
216
+ Returns:
217
+ DataFrame containing the forecast results
218
+ """
219
+
220
+ try:
221
+ df_forecast = df_forecast.copy()
222
+ for col in df_forecast.columns:
223
+ if pd.api.types.is_datetime64_any_dtype(df_forecast[col]):
224
+ df_forecast[col] = df_forecast[col].astype(str)
225
+
226
+ # Convert DataFrame to list of records
227
+ data = df_forecast.to_dict(orient="records")
228
+
229
+ response = requests.post(
230
+ f"{self.api_url}modelforecast_ind/",
231
+ json=data,
232
+ headers=self.headers
233
+ )
234
+
235
+ if response.status_code != 200:
236
+ raise Exception(f"Forecast generation failed: {response.text}")
237
+
238
+ result = pd.DataFrame(response.json())
239
+
240
+ # Clean up memory after operation
241
+ del df_forecast
242
+ del data
243
+ self._cleanup_memory()
244
+
245
+ return result
246
+ except Exception as e:
247
+ self.logger.error(f"Forecast generation failed: {str(e)}")
248
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datfid
3
- Version: 0.1.13
3
+ Version: 0.1.15
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
@@ -2,11 +2,11 @@ from setuptools import setup, find_packages
2
2
 
3
3
  # to build:
4
4
  # 1) open this file at level of datfid-sdk folder
5
- # 2) change version in this file
5
+ # 2) change version in this file and save it
6
6
  # 3) delete folder datfid.egg-info
7
7
  # 4) delete older files from dist folder
8
8
  # 5) in terminal: python setup.py sdist bdist_wheel
9
- # 6) in terminal: twine upload --repository testpypi dist/*
9
+ # 6) in terminal: twine upload --repository pypi dist/*
10
10
  # 7) in hugging face delete older files from dist folder
11
11
  # 8) in hugging face upload updated files
12
12
  # 9) in terminal uninstall older version of datfid: pip uninstall datfid
@@ -17,7 +17,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
17
17
 
18
18
  setup(
19
19
  name="datfid",
20
- version="0.1.13",
20
+ version="0.1.15",
21
21
  description="SDK to access the DATFID API hosted on Hugging Face Spaces",
22
22
  long_description=long_description,
23
23
  long_description_content_type="text/markdown", # Important!
File without changes
File without changes
File without changes
File without changes