[ENH]: Add feature_md5 argument to read_transform() #248
2 changed files with 14 additions and 6 deletions
1
docs/changes/newsfragments/248.change
Normal file
1
docs/changes/newsfragments/248.change
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Add ``feature_md5`` argument to :func:`.read_transform()` by `Synchon Mandal`_
|
||||||
|
|
@ -17,8 +17,9 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
def read_transform(
|
def read_transform(
|
||||||
storage: Type["BaseFeatureStorage"],
|
storage: Type["BaseFeatureStorage"],
|
||||||
feature_name: str,
|
|
||||||
transform: str,
|
transform: str,
|
||||||
|
feature_name: Optional[str] = None,
|
||||||
|
feature_md5: Optional[str] = None,
|
||||||
transform_args: Optional[Tuple] = None,
|
transform_args: Optional[Tuple] = None,
|
||||||
transform_kw_args: Optional[Dict] = None,
|
transform_kw_args: Optional[Dict] = None,
|
||||||
) -> pd.DataFrame:
|
) -> pd.DataFrame:
|
||||||
|
|
@ -28,11 +29,13 @@ def read_transform(
|
||||||
----------
|
----------
|
||||||
storage : storage-like
|
storage : storage-like
|
||||||
The storage class, for example, SQLiteFeatureStorage.
|
The storage class, for example, SQLiteFeatureStorage.
|
||||||
feature_name : str
|
|
||||||
Name of the feature to read.
|
|
||||||
transform : str
|
transform : str
|
||||||
The kind of transform formatted as ``<package>_<function>``,
|
The kind of transform formatted as ``<package>_<function>``,
|
||||||
for example, ``bctpy_degrees_und``.
|
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
|
transform_args : tuple, optional
|
||||||
The positional arguments for the callable of ``transform``
|
The positional arguments for the callable of ``transform``
|
||||||
(default None).
|
(default None).
|
||||||
|
|
@ -62,7 +65,9 @@ def read_transform(
|
||||||
transform_kw_args = transform_kw_args or {}
|
transform_kw_args = transform_kw_args or {}
|
||||||
|
|
||||||
# Read storage
|
# 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
|
# Retrieve package and function
|
||||||
package, func_str = transform.split("_", 1)
|
package, func_str = transform.split("_", 1)
|
||||||
# Condition for package
|
# Condition for package
|
||||||
|
|
@ -105,7 +110,8 @@ def read_transform(
|
||||||
# Apply function and store subject-wise
|
# Apply function and store subject-wise
|
||||||
output_list = []
|
output_list = []
|
||||||
logger.debug(
|
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]):
|
for subject in range(stored_data["data"].shape[2]):
|
||||||
output = func(
|
output = func(
|
||||||
|
|
@ -119,7 +125,8 @@ def read_transform(
|
||||||
idx_df = pd.DataFrame(data=stored_data["element"])
|
idx_df = pd.DataFrame(data=stored_data["element"])
|
||||||
# Create multiindex from dataframe
|
# Create multiindex from dataframe
|
||||||
logger.debug(
|
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)
|
data_idx = pd.MultiIndex.from_frame(df=idx_df)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue