Improve compile_values and related functions#765
Conversation
Codecov Report
Additional details and impacted files |
bennybp
left a comment
There was a problem hiding this comment.
Just some cosmetic changes that make it consistent with everything else. Otherwise good job! :)
| self, | ||
| value_call: Callable, | ||
| value_name: str, | ||
| value_names: Union[List[str], str] = "value", |
There was a problem hiding this comment.
Having the type be Union[Iterable[str], str] would be more generic :)
There was a problem hiding this comment.
Actually, Sequence, not Iterable.
| # Make specification top level index. | ||
| return return_val.swaplevel(axis=1) | ||
|
|
||
| def get_properties_df(self, properties_list: List[str]) -> pd.DataFrame: |
There was a problem hiding this comment.
Also should be Iterable[str]
There was a problem hiding this comment.
Sequence, not Iterable, since order matters
|
|
||
| Parameters | ||
| ----------- | ||
| value_call : Callable |
There was a problem hiding this comment.
We don't use the types in the docstrings, since sphinx can now get the types from the function arguments itself.
|
Looks good! Thanks! |
This PR makes some edits to the
compile_valuesmethod and adds a new dataset method calledget_properties_df.The following changes are made to
compile_values:compile_valuesnow always returns a multi-level index where the specification is the top leve index.compile_valuesnow has an option to unpack results from the callable, allowing more than one dataframe column to be built at a time.entry_namemay be a string or list of strings, but now also has a default value in case the user doesn't provide it.Example use:
The function
get_properties_dfis added to allow easier compilation of record properties into a dataframe. The function takes a list of properties and returns a multi-level index dataframe similar to the type returned fromcompile_values. Under the hood, the function usescompile_valuesaccessing thepropertiesusing.getin case property doesn't exist for a particular specification. Additionally, before the df is returned to the user any columns containing allnanare dropped.Example use (continuing from example above)