Skip to content

Instantly share code, notes, and snippets.

@kylegallatin
Last active July 31, 2022 20:43
Show Gist options
  • Save kylegallatin/35d62a0e7e0524a87ad5815dbe54c7e3 to your computer and use it in GitHub Desktop.
Save kylegallatin/35d62a0e7e0524a87ad5815dbe54c7e3 to your computer and use it in GitHub Desktop.
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
@kylegallatin
Copy link
Author

@anuran-roy thanks for bringing it up! The gists were copied directly from the notebook here that's meant to be runnable e2e - but you're right that as a standalone gist keeping those things as global variables isn't very useful. I'll update it!

@kylegallatin
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment