Skip to content

Commit

Permalink
feat: optional static vars
Browse files Browse the repository at this point in the history
  • Loading branch information
martibosch committed Apr 23, 2024
1 parent 718714f commit ba8ca20
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tstore/tslong/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ def to_tstore(
id_var,
time_var,
ts_variables,
static_variables,
static_variables=None,
# TSTORE options
partitioning=None,
tstore_structure="id-var",
overwrite=True,
):
"""TSLONG.to_tstore()."""
# If index time, remove
df = df.reset_index(names=time_var)
if time_var not in df.columns:
df = df.reset_index(names=time_var)

Check warning on line 72 in tstore/tslong/pandas.py

View check run for this annotation

Codecov / codecov/patch

tstore/tslong/pandas.py#L71-L72

Added lines #L71 - L72 were not covered by tests

# Set identifier as pyarrow large_string !
# - Very important to join attrs at read time !
Expand All @@ -92,8 +93,11 @@ def to_tstore(
partitioning = check_partitioning(partitioning, ts_variables=list(ts_variables))

# Identify static dataframe (attributes)
attr_cols = [id_var]
if static_variables is not None:
attr_cols += static_variables

Check warning on line 98 in tstore/tslong/pandas.py

View check run for this annotation

Codecov / codecov/patch

tstore/tslong/pandas.py#L96-L98

Added lines #L96 - L98 were not covered by tests
# - TODO: add flag to check if are actual duplicates !
df_attrs = df[[id_var, *static_variables]]
df_attrs = df[attr_cols]

Check warning on line 100 in tstore/tslong/pandas.py

View check run for this annotation

Codecov / codecov/patch

tstore/tslong/pandas.py#L100

Added line #L100 was not covered by tests
df_attrs = df_attrs.drop_duplicates(subset=id_var)
df_attrs = df_attrs.reset_index(drop=True)

Expand All @@ -120,7 +124,6 @@ def to_tstore(
# Write to disk per identifier
for tstore_id, df_group in df.groupby(id_var):
for ts_variable, columns in ts_variables.items():

# Retrieve columns of the TS object
if columns is None:
columns = [ts_variable]
Expand Down

0 comments on commit ba8ca20

Please sign in to comment.