Last active
July 31, 2022 20:43
-
-
Save kylegallatin/35d62a0e7e0524a87ad5815dbe54c7e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterable, Callable, Dict | |
class SuperSimpleFeatureStore: | |
def __init__(self, dataframe: pd.DataFrame): | |
self.dataframe = dataframe | |
self.feature_dict = dataframe.set_index("user_id").T.to_dict() | |
def register_feature(self, name: str, feature_definition: Callable) -> None: | |
for key in self.feature_dict: | |
self.feature_dict[key][name] = feature_definition(self.feature_dict[key]) | |
def get_user_feature(self, user_id: str) -> Dict: | |
return self.feature_dict.get(user_id) | |
def get_all_data(self) -> pd.DataFrame: | |
return pd.DataFrame(self.feature_dict).T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh but that is actually just a straight up error, using the constructor argument on one line and a previously defined variable on another. Thanks for bringing it up! I've fixed it.