Skip to content

Commit 7b0f8f0

Browse files
authored
Add Additional Args for Store Multiple TS Function (#276)
* Ensure we expose the multi thread option and enable store_multi_ts to handle needed params * Update the multi ts tests to include the new kwargs * Patch bump * Set multithread default to true
1 parent e27837c commit 7b0f8f0

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

cwms/timeseries/timeseries.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ def timeseries_df_to_json(
469469
def store_multi_timeseries_df(
470470
data: pd.DataFrame,
471471
office_id: str,
472+
create_as_ltrs: Optional[bool] = False,
473+
store_rule: Optional[str] = None,
474+
override_protection: Optional[bool] = False,
475+
multithread: Optional[bool] = True,
472476
max_workers: Optional[int] = 30,
473477
) -> None:
474478
"""stored mulitple timeseries from a dataframe. The dataframe must be a metled dataframe with columns
@@ -489,6 +493,19 @@ def store_multi_timeseries_df(
489493
2 2023-12-20T15:15:00.000-05:00 98.5 0 OMA.Stage.Inst.6Hours.0.Fcst-MRBWM-GRFT ft 2024-04-22 07:15:00-05:00
490494
office_id: string
491495
The owning office of the time series(s).
496+
create_as_ltrs: bool, optional, default is False
497+
Flag indicating if timeseries should be created as Local Regular Time Series.
498+
store_rule: str, optional, default is None:
499+
The business rule to use when merging the incoming with existing data. Available values :
500+
REPLACE_ALL,
501+
DO_NOT_REPLACE,
502+
REPLACE_MISSING_VALUES_ONLY,
503+
REPLACE_WITH_NON_MISSING,
504+
DELETE_INSERT.
505+
override_protection: bool, optional, default is False
506+
A flag to ignore the protected data quality flag when storing data.
507+
multithread: bool, default is false
508+
Specifies whether to store chunked time series values using multiple threads.
492509
max_workers: Int, Optional, default is None
493510
It is a number of Threads aka size of pool in concurrent.futures.ThreadPoolExecutor.
494511
@@ -502,7 +519,6 @@ def store_ts_ids(
502519
ts_id: str,
503520
office_id: str,
504521
version_date: Optional[datetime] = None,
505-
multithread: bool = False,
506522
) -> None:
507523
try:
508524
units = data["units"].iloc[0]
@@ -513,7 +529,13 @@ def store_ts_ids(
513529
office_id=office_id,
514530
version_date=version_date,
515531
)
516-
store_timeseries(data=data_json, multithread=multithread)
532+
store_timeseries(
533+
data=data_json,
534+
create_as_ltrs=create_as_ltrs,
535+
store_rule=store_rule,
536+
override_protection=override_protection,
537+
multithread=multithread,
538+
)
517539
except Exception as e:
518540
print(f"Error processing {ts_id}: {e}")
519541
return None

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "cwms-python"
33
repository = "https://github.com/HydrologicEngineeringCenter/cwms-python"
44

5-
version = "1.0.6"
5+
version = "1.0.7"
66

77
packages = [
88
{ include = "cwms" },

tests/cda/timeseries/timeseries_CDA_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ def test_store_multi_timeseries_df():
184184
"units": ["ft", "ft"],
185185
}
186186
)
187-
ts.store_multi_timeseries_df(df, TEST_OFFICE)
187+
ts.store_multi_timeseries_df(
188+
df,
189+
TEST_OFFICE,
190+
store_rule="REPLACE_ALL",
191+
override_protection=False,
192+
)
188193
data1 = ts.get_timeseries(
189194
TEST_TSID_MULTI, TEST_OFFICE, multithread=False, begin=BEGIN, end=END
190195
).json
@@ -203,7 +208,13 @@ def test_store_multi_timeseries_df():
203208

204209
def test_store_multi_timeseries_chunks_df():
205210
# test getting multi timeseries while using the chunk method as well
206-
ts.store_multi_timeseries_df(data=DF_MULTI_TIMESERIES, office_id=TEST_OFFICE)
211+
ts.store_multi_timeseries_df(
212+
data=DF_MULTI_TIMESERIES,
213+
office_id=TEST_OFFICE,
214+
store_rule="REPLACE_ALL",
215+
override_protection=False,
216+
multithread=True,
217+
)
207218
data1 = ts.get_timeseries(
208219
ts_id=TEST_TSID_MULTI1,
209220
office_id=TEST_OFFICE,

0 commit comments

Comments
 (0)