Skip to content

Commit

Permalink
Lazy-load pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Nov 8, 2024
1 parent 4ebcd88 commit a433387
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions qcportal/qcportal/dataset_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
Mapping,
)

import pandas as pd

try:
import pydantic.v1 as pydantic
from pydantic.v1 import BaseModel, Extra, validator, PrivateAttr, Field
Expand All @@ -40,6 +38,7 @@

if TYPE_CHECKING:
from qcportal.client import PortalClient
from pandas import DataFrame


class Citation(BaseModel):
Expand Down Expand Up @@ -1422,7 +1421,7 @@ def compile_values(
entry_names: Optional[Union[str, Iterable[str]]] = None,
specification_names: Optional[Union[str, Iterable[str]]] = None,
unpack: bool = False,
) -> pd.DataFrame:
) -> "DataFrame":
"""
Compile values from records into a pandas DataFrame.
Expand Down Expand Up @@ -1450,7 +1449,7 @@ def compile_values(
Returns
--------
pd.DataFrame
pandas.DataFrame
A multi-index DataFrame where each row corresponds to an entry. Each column corresponds has a top level
index as a specification, and a second level index as the appropriate value name.
Values are extracted from records using 'value_call'.
Expand All @@ -1468,6 +1467,8 @@ def compile_values(
to be distributed across columns in the resulting DataFrame. 'value_call' should always return the
same number of values for each record if unpack is True.
"""
import pandas as pd


def _data_generator(unpack=False):
for entry_name, spec_name, record in self.iterate_records(
Expand Down Expand Up @@ -1511,7 +1512,7 @@ def _check_first():
# Make specification top level index.
return return_val.swaplevel(axis=1)

def get_properties_df(self, properties_list: Sequence[str]) -> pd.DataFrame:
def get_properties_df(self, properties_list: Sequence[str]) -> "DataFrame":
"""
Retrieve a DataFrame populated with the specified properties from dataset records.
Expand All @@ -1528,7 +1529,7 @@ def get_properties_df(self, properties_list: Sequence[str]) -> pd.DataFrame:
Returns:
--------
pd.DataFrame
pandas.DataFrame
A DataFrame populated with the specified properties for each record.
"""

Expand Down

0 comments on commit a433387

Please sign in to comment.