Skip to content

Commit

Permalink
STYLE: Format with black (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickEdwards7502 committed Sep 19, 2024
1 parent 209a463 commit b94afcc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions python/varspark/featuresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pandas as pd
from typedecorator import params, Nullable


class FeatureSource(object):
def __init__(self, _jvm, _vs_api, _jsql, sql, _jfs):
self._jfs = _jfs
Expand All @@ -12,7 +13,7 @@ def __init__(self, _jvm, _vs_api, _jsql, sql, _jfs):

@params(sample_list_str=str)
def extract_samples(sample_list_str):
""" Convert the sample list string to a list of sample names.
"""Convert the sample list string to a list of sample names.
:param (str) sample_list_str: The string representation of the sample list.
Expand All @@ -23,29 +24,32 @@ def extract_samples(sample_list_str):

@params(feature=object)
def unpack_feature_data(feature):
""" Unpack feature data from byte array into a tuple of integers.
"""Unpack feature data from byte array into a tuple of integers.
:param feature: The feature object containing the data.
return tuple: A tuple containing unpacked integers.
"""
byte_string = feature.data().valueAsByteArray()
format_string = f'{len(byte_string)}B'
format_string = f"{len(byte_string)}B"
return struct.unpack(format_string, byte_string)

@params(features_ref=object)
def collect_feature_data(features_ref):
""" Collect and organize feature data into a dictionary.
"""Collect and organize feature data into a dictionary.
:param features_ref: The list of feature objects.
:return dict: A dictionary with feature labels as keys and unpacked data as values.
"""
return {feature.label(): FeatureSource.unpack_feature_data(feature) for feature in features_ref}
return {
feature.label(): FeatureSource.unpack_feature_data(feature)
for feature in features_ref
}

@params(self=object, scala=Nullable(bool))
def to_df(self, scala=False):
""" Converts a Feature Source RDD to a pandas dataframe.
"""Converts a Feature Source RDD to a pandas dataframe.
:param (bool) scala: Indicates whether to use the scala version of DataFrame conversion
Expand All @@ -56,7 +60,7 @@ def to_df(self, scala=False):
jdf.count()
jdf.createOrReplaceTempView("df")
features = self.sql.table("df").toPandas()
features.set_index('variant_id', inplace=True)
features.set_index("variant_id", inplace=True)
return features
else:
features_ref = self._jfs.features().collect()
Expand Down

0 comments on commit b94afcc

Please sign in to comment.