Skip to content

Commit

Permalink
improve docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
diehlbw committed Jun 26, 2024
1 parent cd63f76 commit cefb730
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/seismometer/data/loader/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ def __init__(
The loaded configuration object.
prediction_fn : ConfigOnlyHook
A callable taking a ConfigProvider and returning a dataframe.
Used to load a (predictions) dataframe based on configuration.
Used to load a (predictions) dataframe based on configuration;
skipped if prediction_obj is provided to load_data.
event_fn : ConfigOnlyHook, optional
A callable taking a ConfigProvider and returning a dataframe.
Used to load a (events) dataframe based on configuration.
Used to load a (events) dataframe based on configuration; skipped if event_obj is provided to load_data.
post_predict_fn : ConfigFrameHook, optional
A callable taking a ConfigProvider and a (predictions) dataframe and returning a dataframe.
Used to do minor transforms of predictions such as type casting.
Expand Down Expand Up @@ -121,7 +122,7 @@ def load_data(self, prediction_obj: pd.DataFrame = None, event_obj: pd.DataFrame
the loaded and merged dataframe for a Seismogram session.
"""

logger.info(f"Importing files from {self.config.config_dir}")
logger.info(f"Configuration speficies path {self.config.config_dir}")

dataframe = self._load_predictions(prediction_obj)
dataframe = self.post_predict_fn(self.config, dataframe)
Expand All @@ -130,7 +131,7 @@ def load_data(self, prediction_obj: pd.DataFrame = None, event_obj: pd.DataFrame
return dataframe

def _load_predictions(self, prediction_obj: pd.DataFrame = None):
"""Load predictions from config or memory."""
"""Load predictions from configuration if not passed in directly."""
if (prediction_obj is None) and (self.prediction_fn is None):
raise RuntimeError(
"No prediction_fn provided and no prediction_obj provided. A prediction frame must be provided."
Expand All @@ -140,7 +141,10 @@ def _load_predictions(self, prediction_obj: pd.DataFrame = None):
return self.prediction_from_memory(self.config, prediction_obj)

def _add_events(self, dataframe: pd.DataFrame, event_obj: pd.DataFrame = None):
"""Load and merge events onto the predictions dataframe."""
"""
Load and merge events onto the predictions dataframe.
Prioritizes event_obj if provided, else loads from configuration.
"""
event_frame = self._load_events(event_obj)
if event_frame.empty: # No events to add
logger.debug("No events were loaded; nothing added to frame.")
Expand Down
2 changes: 1 addition & 1 deletion tests/data/loaders/test_load_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_loading_can_log_location(self, fake_config, caplog):
with caplog.at_level("INFO"):
_ = loader.load_data(input)

assert "Importing" in caplog.text
assert "Configuration speficies" in caplog.text

@pytest.mark.parametrize(
"input,expected",
Expand Down

0 comments on commit cefb730

Please sign in to comment.