Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow entry and specification names to be passed to get_properties_df #900

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions qcportal/qcportal/dataset_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,12 @@ def _check_first():
# Make specification top level index.
return return_val.swaplevel(axis=1)

def get_properties_df(self, properties_list: Sequence[str]) -> "DataFrame":
def get_properties_df(
self,
properties_list: Sequence[str],
entry_names: Sequence[str] | None = None,
specification_names: Sequence[str] | None = None,
) -> "DataFrame":
"""
Retrieve a DataFrame populated with the specified properties from dataset records.

Expand All @@ -2011,6 +2016,12 @@ def get_properties_df(self, properties_list: Sequence[str]) -> "DataFrame":
properties_list
List of property names to retrieve from the records.

entry_names
Entry names to filter records. If not provided, considers all entries.

specification_names
Specification names to filter records. If not provided, considers all specifications.

Returns:
--------
pandas.DataFrame
Expand All @@ -2021,7 +2032,13 @@ def get_properties_df(self, properties_list: Sequence[str]) -> "DataFrame":
extract_properties = lambda x: [x.properties.get(property_name) for property_name in properties_list]

# retrieve values.
result = self.compile_values(extract_properties, value_names=properties_list, unpack=True)
result = self.compile_values(
extract_properties,
value_names=properties_list,
unpack=True,
specification_names=specification_names,
entry_names=entry_names,
)

# Drop columns with all nan values. This will occur if a property that is not part of a
# specification is requested.
Expand Down
Loading