Skip to content

Commit

Permalink
fix(datasets/combine): add ability to load dataframe from path or str…
Browse files Browse the repository at this point in the history
…ing in merge process
  • Loading branch information
entelecheia committed Aug 13, 2023
1 parent 7466634 commit 8a9d510
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hyfi/utils/datasets/combine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Dataset transformation functions. Concatenate, merge, join, etc.
"""
from pathlib import Path
from typing import Dict, List, Optional, Sequence, Tuple, Union

import datasets as hfds
Expand All @@ -11,6 +12,7 @@

from hyfi.utils.logging import LOGGING

from .load import DSLoad
from .types import DatasetType

logger = LOGGING.getLogger(__name__)
Expand Down Expand Up @@ -123,8 +125,8 @@ def concatenate_datasets(

@staticmethod
def merge_dataframes(
left: pd.DataFrame,
right: pd.DataFrame,
data: pd.DataFrame,
right: Union[str, Path, pd.DataFrame],
how: str = "inner",
on: Optional[Union[str, List[str]]] = None,
left_on: Optional[Union[str, List[str]]] = None,
Expand Down Expand Up @@ -172,7 +174,9 @@ def merge_dataframes(
"""
if verbose:
logger.info("Merging dataframes")
return left.merge(
if isinstance(right, (str, Path)):
right = DSLoad.load_dataframe(right)
return data.merge(
right,
how=how,
on=on,
Expand Down

0 comments on commit 8a9d510

Please sign in to comment.