Skip to content

Commit

Permalink
Merge pull request #248 from juaml/update/read_transform_feature_md5
Browse files Browse the repository at this point in the history
[ENH]: Add `feature_md5` argument to `read_transform()`
  • Loading branch information
synchon authored Aug 3, 2023
2 parents dc23879 + 3f8febc commit e3e9423
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/248.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``feature_md5`` argument to :func:`.read_transform()` by `Synchon Mandal`_
19 changes: 13 additions & 6 deletions junifer/onthefly/read_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

def read_transform(
storage: Type["BaseFeatureStorage"],
feature_name: str,
transform: str,
feature_name: Optional[str] = None,
feature_md5: Optional[str] = None,
transform_args: Optional[Tuple] = None,
transform_kw_args: Optional[Dict] = None,
) -> pd.DataFrame:
Expand All @@ -28,11 +29,13 @@ def read_transform(
----------
storage : storage-like
The storage class, for example, SQLiteFeatureStorage.
feature_name : str
Name of the feature to read.
transform : str
The kind of transform formatted as ``<package>_<function>``,
for example, ``bctpy_degrees_und``.
feature_name : str, optional
Name of the feature to read (default None).
feature_md5 : str, optional
MD5 hash of the feature to read (default None).
transform_args : tuple, optional
The positional arguments for the callable of ``transform``
(default None).
Expand Down Expand Up @@ -62,7 +65,9 @@ def read_transform(
transform_kw_args = transform_kw_args or {}

# Read storage
stored_data = storage.read(feature_name=feature_name) # type: ignore
stored_data = storage.read(
feature_name=feature_name, feature_md5=feature_md5
) # type: ignore
# Retrieve package and function
package, func_str = transform.split("_", 1)
# Condition for package
Expand Down Expand Up @@ -105,7 +110,8 @@ def read_transform(
# Apply function and store subject-wise
output_list = []
logger.debug(
f"Computing '{package}.{func_str}' for feature {feature_name} ..."
f"Computing '{package}.{func_str}' for feature "
f"{feature_name or feature_md5} ..."
)
for subject in range(stored_data["data"].shape[2]):
output = func(
Expand All @@ -119,7 +125,8 @@ def read_transform(
idx_df = pd.DataFrame(data=stored_data["element"])
# Create multiindex from dataframe
logger.debug(
f"Generating pandas.MultiIndex for feature {feature_name} ..."
"Generating pandas.MultiIndex for feature "
f"{feature_name or feature_md5} ..."
)
data_idx = pd.MultiIndex.from_frame(df=idx_df)

Expand Down

0 comments on commit e3e9423

Please sign in to comment.