psr-factory 5.0.0b67__py3-none-win_amd64.whl → 5.0.0b69__py3-none-win_amd64.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.
psr/factory/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
- # PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
2
- # Unauthorized copying of this file, via any medium is strictly prohibited
3
- # Proprietary and confidential
4
-
5
- __version__ = "5.0.0b67"
6
-
7
- from .api import *
1
+ # PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
2
+ # Unauthorized copying of this file, via any medium is strictly prohibited
3
+ # Proprietary and confidential
4
+
5
+ __version__ = "5.0.0b69"
6
+
7
+ from .api import *
psr/factory/api.py CHANGED
@@ -1080,11 +1080,11 @@ class DataObject(_BaseObject):
1080
1080
 
1081
1081
  def __repr__(self):
1082
1082
  identifiers = []
1083
- if self.code != 0:
1083
+ if self.has_code():
1084
1084
  identifiers.append(f"code={self.code}")
1085
- if self.id != "":
1085
+ if self.has_id():
1086
1086
  identifiers.append(f"id={self.id.strip()}")
1087
- if self.name != "":
1087
+ if self.has_name():
1088
1088
  identifiers.append(f"name={self.name.strip()}")
1089
1089
  return f"psr.factory.DataObject({self.type}, {', '.join(identifiers)})"
1090
1090
 
@@ -1237,19 +1237,19 @@ class DataObject(_BaseObject):
1237
1237
  if _err.code != 0:
1238
1238
  raise FactoryException(_err.what)
1239
1239
 
1240
- def set_df(self, dataframe_like):
1241
- if not _has_pandas():
1242
- raise ModuleNotFoundError("pandas required.")
1243
- dataframe_like = pandas.api.interchange.from_dataframe(dataframe_like)
1240
+ def set_df(self, dataframe_like: DataFrameLike):
1244
1241
  df_builder = _DataFrameBuilder()
1245
- _df = df_builder.build_from_pandas(dataframe_like)
1242
+ if _has_pandas() and isinstance(dataframe_like, pandas.DataFrame):
1243
+ _df = df_builder.build_from_pandas(dataframe_like)
1244
+ elif _has_polars() and isinstance(dataframe_like, polars.DataFrame):
1245
+ _df = df_builder.build_from_polars(dataframe_like)
1246
+ else:
1247
+ raise FactoryException("No supported DataFrame library is available.")
1246
1248
  _err = Error()
1247
- factorylib.lib.psrd_object_set_table(self._hdr, _df.handler(),
1248
- _err.handler())
1249
+ factorylib.lib.psrd_object_set_table(self._hdr, _df.handler(), _err.handler())
1249
1250
  if _err.code != 0:
1250
1251
  raise FactoryException(_err.what)
1251
1252
 
1252
-
1253
1253
  def clear_values(self, expression: str):
1254
1254
  _err = Error()
1255
1255
  factorylib.lib.psrd_object_clear_values(self._hdr,
@@ -1281,6 +1281,14 @@ class DataObject(_BaseObject):
1281
1281
  object_list._hdr = ref
1282
1282
  return object_list.to_list()
1283
1283
 
1284
+ def has_code(self) -> bool:
1285
+ _err = Error()
1286
+ bool_value = ctypes.c_bool()
1287
+ factorylib.lib.psrd_object_has_code(self._hdr, ctypes.byref(bool_value), _err.handler())
1288
+ if _err.code != 0:
1289
+ raise FactoryException(_err.what)
1290
+ return bool(bool_value.value)
1291
+
1284
1292
  @property
1285
1293
  def code(self) -> int:
1286
1294
  _err = Error()
@@ -1354,6 +1362,14 @@ class DataObject(_BaseObject):
1354
1362
  def key(self):
1355
1363
  raise AttributeError("do not delete key")
1356
1364
 
1365
+ def has_name(self) -> bool:
1366
+ _err = Error()
1367
+ bool_value = ctypes.c_bool()
1368
+ factorylib.lib.psrd_object_has_name(self._hdr, ctypes.byref(bool_value), _err.handler())
1369
+ if _err.code != 0:
1370
+ raise FactoryException(_err.what)
1371
+ return bool(bool_value.value)
1372
+
1357
1373
  @property
1358
1374
  def name(self) -> str:
1359
1375
  err = Error()
@@ -1382,6 +1398,14 @@ class DataObject(_BaseObject):
1382
1398
  def name(self):
1383
1399
  raise AttributeError("do not delete name")
1384
1400
 
1401
+ def has_id(self) -> bool:
1402
+ _err = Error()
1403
+ bool_value = ctypes.c_bool()
1404
+ factorylib.lib.psrd_object_has_id(self._hdr, ctypes.byref(bool_value), _err.handler())
1405
+ if _err.code != 0:
1406
+ raise FactoryException(_err.what)
1407
+ return bool(bool_value.value)
1408
+
1385
1409
  @property
1386
1410
  def id(self) -> str:
1387
1411
  err = Error()
@@ -1905,6 +1929,8 @@ def _polars_dtype_to_column_type(dtype: "polars.datatypes.classes.DataTypeClass"
1905
1929
  return 4
1906
1930
  if dtype == polars.String:
1907
1931
  return 5
1932
+ if dtype == polars.Boolean:
1933
+ return 1 # TODO: create a boolean column type
1908
1934
  else:
1909
1935
  raise FactoryException(f"Unsupported polars dtype \"{dtype}\".")
1910
1936
 
@@ -2311,7 +2337,7 @@ class _DataFrameBuilder:
2311
2337
  return df
2312
2338
 
2313
2339
  def build_polars_dataframe(self, **kwargs) -> "polars.DataFrame":
2314
- use_object_dtype = kwargs.get("use_object_dtype", True)
2340
+ use_object_dtype = kwargs.get("use_object_dtype", False)
2315
2341
  if not _has_polars():
2316
2342
  raise ModuleNotFoundError("polars required.")
2317
2343
  def convert_column_values(column_name:str, values):
@@ -2325,13 +2351,13 @@ class _DataFrameBuilder:
2325
2351
  data = {column.name: convert_column_values(column.name, column.values)
2326
2352
  for column in self.indices + self.columns}
2327
2353
  if use_object_dtype:
2328
- return polars.DataFrame(data=data, dtype=object)
2354
+ return polars.DataFrame({k: polars.Series(k, v, dtype=polars.Object) for k, v in data.items()})
2329
2355
  else:
2330
2356
  return polars.DataFrame(data=data)
2331
2357
 
2332
2358
  def build_from_polars(self, table_data: "polars.DataFrame") -> "DataFrame":
2333
2359
  # check if the table has indices and if its multi-index or common index
2334
- index_names = ("year", "week", "month", "hour", "scenario", "block", "stage")
2360
+ index_names = ("year", "week", "month", "hour", "scenario", "block", "stage", "date")
2335
2361
  column_index = 0
2336
2362
  data_columns = table_data.columns[:]
2337
2363
  if len(self.column_names) != len(set(self.column_names)):
psr/factory/factory.dll CHANGED
Binary file
psr/factory/factorylib.py CHANGED
@@ -157,14 +157,20 @@ def initialize():
157
157
  lib.psrd_object_get_key.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
158
158
  lib.psrd_object_set_key.restype = ctypes.c_int
159
159
  lib.psrd_object_set_key.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
160
+ lib.psrd_object_has_code.restype = ctypes.c_int
161
+ lib.psrd_object_has_code.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
160
162
  lib.psrd_object_get_code.restype = ctypes.c_int
161
163
  lib.psrd_object_get_code.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
162
164
  lib.psrd_object_set_code.restype = ctypes.c_int
163
165
  lib.psrd_object_set_code.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p]
166
+ lib.psrd_object_has_name.restype = ctypes.c_int
167
+ lib.psrd_object_has_name.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
164
168
  lib.psrd_object_get_name.restype = ctypes.c_int
165
169
  lib.psrd_object_get_name.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
166
170
  lib.psrd_object_set_name.restype = ctypes.c_int
167
171
  lib.psrd_object_set_name.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
172
+ lib.psrd_object_has_id.restype = ctypes.c_int
173
+ lib.psrd_object_has_id.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
168
174
  lib.psrd_object_get_id.restype = ctypes.c_int
169
175
  lib.psrd_object_get_id.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
170
176
  lib.psrd_object_set_id.restype = ctypes.c_int
Binary file
psr/runner/runner.py CHANGED
@@ -236,6 +236,18 @@ def _get_optgen_executable_parent_path(optgen_path: Union[str, pathlib.Path]) ->
236
236
  optgen_path = os.path.realpath(optgen_path)
237
237
  return optgen_path
238
238
 
239
+ def _get_optmain_executable_parent_path(optmain_path: Union[str, pathlib.Path]) -> str:
240
+ if os.name == 'nt':
241
+ model_path = os.path.join(optmain_path, "models", "optmain")
242
+ if os.path.exists(model_path):
243
+ return model_path
244
+ else:
245
+ return os.path.join(optmain_path, "Model")
246
+ else:
247
+ # solve symlinks, if needed
248
+ optmain_path = os.path.realpath(optmain_path)
249
+ return optmain_path
250
+
239
251
 
240
252
  def get_sddp_version(sddp_path: Union[str, pathlib.Path]) -> str:
241
253
  sddp_path = str(sddp_path)
@@ -320,6 +332,17 @@ def run_optgen_cleanup(case_path: Union[str, pathlib.Path], optgen_path: Union[s
320
332
  kwargs["_mode"] = "clean"
321
333
  run_optgen(case_path, optgen_path, sddp_path, **kwargs)
322
334
 
335
+
336
+ def run_optmain(case_path: Union[str, pathlib.Path], optmain_path: Union[str, pathlib.Path], **kwargs):
337
+ case_path = os.path.abspath(str(case_path)).replace("\\", "/") + "/"
338
+ optmain_path = str(optmain_path)
339
+ optmain_path_full = _get_optmain_executable_parent_path(optmain_path)
340
+
341
+ with change_cwd(optmain_path_full):
342
+ cmd = f'optmain {case_path}'
343
+ exec_cmd(cmd, **kwargs)
344
+
345
+
323
346
  def run_psrio(case_path, sddp_path: str, **kwargs):
324
347
  recipe_script = kwargs.get('r', kwargs.get('recipes', False))
325
348
  output_path = kwargs.get('o', kwargs.get('output', False))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: psr-factory
3
- Version: 5.0.0b67
3
+ Version: 5.0.0b69
4
4
  Summary: PSR database management module.
5
5
  Author-email: "PSR Inc." <psrfactory@psr-inc.com>
6
6
  License-Expression: MIT
@@ -6,12 +6,13 @@ psr/execqueue/config.py,sha256=F8sp-JGeoRspQRR63SjSKV5wDz0OVGnA-cNm1UDYHBY,1693
6
6
  psr/execqueue/db.py,sha256=T3EWiK_2USmgNKTiVaavbqnS-EklCCZKsScOtdD6FgM,10853
7
7
  psr/execqueue/server.py,sha256=0N5_ekXj1h5A1QyI4xPmTDpYlAo-qQfLWAa-TL0syWI,28781
8
8
  psr/execqueue/watcher.py,sha256=R1dyXJ-OYn_QjqdItBwbLJZQ2LcbtdHqnRaYkyphi4w,5637
9
- psr/factory/__init__.py,sha256=KSv5D-MDslXpdDYG_dS2AepstsHOHOrJvQftXoA9b5E,219
10
- psr/factory/api.py,sha256=7rk0qAs36xUQFKyct8CWHh5wfGct-Vi-MH4wsSDa330,113875
11
- psr/factory/factory.dll,sha256=TqrlyNj9edTZxMz3RmfD1yeAJ_RuktXLdF2SVW3v12k,20271952
9
+ psr/factory/__init__.py,sha256=SDxMzOm1aV-IMUXaahBqoutgc1lBZ69rE4YfLaROy1w,212
10
+ psr/factory/api.py,sha256=PK0OpX4AtHE2u25vmaornVR4XU5jbwiQiTGlAlVPvao,115062
11
+ psr/factory/factory.dll,sha256=QHD1k65DWU4jzQSOjw4DQVgR4IxF-t_Q6IAr98TMOOo,20277584
12
12
  psr/factory/factory.pmd,sha256=wPTJucfpUxc7vyeldE-caD4TqJiT_dCbl-DY2zOkq8c,252791
13
13
  psr/factory/factory.pmk,sha256=WrSXrK3zR_7v4cOVppRGWehnLhnZFSFWHnjyA9OUe00,607612
14
- psr/factory/factorylib.py,sha256=VV8CtwH30k5YItDn6SVo1o5LFJ_IG2WZjs0F1eIimcs,30750
14
+ psr/factory/factorylib.py,sha256=-i_3j_dkCKZA_hpCePD7_qdGOqD8o89mwzqKmvya_EI,31226
15
+ psr/factory/libcurl-x64.dll,sha256=6WGBmqX4q_eD8Vc0E2VpCvVrFV3W7TQoaKqSdbhXBu0,5313096
15
16
  psr/factory/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
17
  psr/factory/samples/__init__.py,sha256=xxOch5Fokzjy571a6OHD87FWM17qKgvfcbr8xn-n36I,80
17
18
  psr/factory/samples/sddp_case01.py,sha256=h0iVqswPeOzauikiHjwUiPRQbmIQjECPcGkX54G1Clo,5060
@@ -23,10 +24,10 @@ psr/psrfcommon/__init__.py,sha256=WXR560XQllIjtFpWd0jiJEbUAQIyh5-6lwj-42_J95c,20
23
24
  psr/psrfcommon/psrfcommon.py,sha256=LOuojeKX51eCMcPwpfDgRnGlK6WpS5UwDxQajbdRb5I,1571
24
25
  psr/psrfcommon/tempfile.py,sha256=5S13wa2DCLYTUdwbLm_KMBRnDRJ0WDlu8GO2BmZoNdg,3939
25
26
  psr/runner/__init__.py,sha256=kI9HDX-B_LMQJUHHylFHas2rNpWfNNa0pZXoIvX_Alw,230
26
- psr/runner/runner.py,sha256=DN5oEPaQo7_LtYjoQgyLiiMBcwrDCUzbjXfWql6bNEI,29484
27
+ psr/runner/runner.py,sha256=bgxZAvlgroe_F9QCInp9XbTVfSMSwjbpLEei5FeAxao,30352
27
28
  psr/runner/version.py,sha256=mch2Y8anSXGMn9w72Z78PhSRhOyn55EwaoLAYhY4McE,194
28
- psr_factory-5.0.0b67.dist-info/licenses/LICENSE.txt,sha256=N6mqZK2Ft3iXGHj-by_MHC_dJo9qwn0URjakEPys3H4,1089
29
- psr_factory-5.0.0b67.dist-info/METADATA,sha256=DYdTRa9suJAe0ffO9EZFjNZ0w8pwhWTaEVwXy4NzsDM,1914
30
- psr_factory-5.0.0b67.dist-info/WHEEL,sha256=ZjXRCNaQ9YSypEK2TE0LRB0sy2OVXSszb4Sx1XjM99k,97
31
- psr_factory-5.0.0b67.dist-info/top_level.txt,sha256=Jb393O96WQk3b5D1gMcrZBLKJJgZpzNjTPoldUi00ck,4
32
- psr_factory-5.0.0b67.dist-info/RECORD,,
29
+ psr_factory-5.0.0b69.dist-info/licenses/LICENSE.txt,sha256=N6mqZK2Ft3iXGHj-by_MHC_dJo9qwn0URjakEPys3H4,1089
30
+ psr_factory-5.0.0b69.dist-info/METADATA,sha256=-1mvIhGhrAzHEVozKeJcccVfT1dvU7dCf5koKzWIvBA,1914
31
+ psr_factory-5.0.0b69.dist-info/WHEEL,sha256=ZjXRCNaQ9YSypEK2TE0LRB0sy2OVXSszb4Sx1XjM99k,97
32
+ psr_factory-5.0.0b69.dist-info/top_level.txt,sha256=Jb393O96WQk3b5D1gMcrZBLKJJgZpzNjTPoldUi00ck,4
33
+ psr_factory-5.0.0b69.dist-info/RECORD,,