Example #1
0
    def __init__(
            self,
            left: pd.DataFrame,
            right: pd.DataFrame,
            on=None,
            left_on=None,
            right_on=None,
            merge_suffixes=get_option("operators.binary.column_suffixes"),
            add_suffixes=False,
            add_indexes=(None, None),
    ):

        self.left = self.orig_left = left
        self.right = self.orig_right = right

        self.on = lltools.maybe_make_list(on)
        self.left_on = lltools.maybe_make_list(left_on)
        self.right_on = lltools.maybe_make_list(right_on)

        self.merge_suffixes = merge_suffixes

        self.add_suffixes = validatortools.validate_bool_kwarg(
            add_suffixes, "add_suffixes")

        self.add_indexes = add_indexes

        self._validate_specification()
Example #2
0
 def replace_tag(self, old_tag, new_tag):
     """Replace ``old_tag`` with ``new_tag``."""
     if set(old_tag).issubset(set(self._tags)):
         old_tag = lltools.maybe_make_list(old_tag)
         new_tag = lltools.maybe_make_list(new_tag)
         for ot in old_tag:
             self._tags.remove(ot)
         self._tags.extend(new_tag)
Example #3
0
    def keep_cols(self, cols, inplace=False):
        """Keep specified columns (thus dropping the rest).
        Note: `Key` columns will always be kept.
        """
        cols_to_keep = self.key_cols

        # preserve order of the key columns by sorting them according
        # to existing order
        cols_to_keep.sort(key=lambda i: self.columns.tolist().index(i))

        cols = lltools.maybe_make_list(cols)
        cols_to_keep.extend([c for c in cols if c not in cols_to_keep])

        result = self[cols_to_keep]
        if inplace:
            return self._update_inplace(result)
        else:
            return result
Example #4
0
 def mappers(self, mappers):
     self._mappers = []
     mappers = lltools.maybe_make_list(mappers)
     for mapper in mappers:
         self.add_mapper(mapper)
Example #5
0
def test_maybe_make_list():
    assert lltools.maybe_make_list("a") == ["a"]
    assert lltools.maybe_make_list(["a"]) == ["a"]
    assert lltools.maybe_make_list(("a",)) == ("a",)
    def __init__(
        self,
        left: pd.DataFrame,
        right: pd.DataFrame,
        id_on=None,
        id_left_on=None,
        id_right_on=None,
        date_on=None,
        date_left_on=None,
        date_right_on=None,
        get: str = "all",
        when: str = "earlier_or_later",
        days: int = 90,
        left_link_id=None,
        dropna: bool = False,
        drop_duplicates: bool = False,
        duplicates_indicator: bool = False,
        merge="partial",
        merge_suffixes=get_option("operators.binary.column_suffixes"),
        prepend_levels=(None, None),
    ):
        self.left = left
        self.right = right

        self.id_on = lltools.maybe_make_list(id_on)
        self.id_left_on = lltools.maybe_make_list(id_left_on)
        self.id_right_on = lltools.maybe_make_list(id_right_on)

        self.date_on = date_on
        self.date_left_on = date_left_on
        self.date_right_on = date_right_on

        self.get = get
        self.when = when
        self.days = days

        self.left_link_id = left_link_id

        self.dropna = validatortools.validate_bool_kwarg(dropna, "dropna")
        self.drop_duplicates = validatortools.validate_bool_kwarg(
            drop_duplicates, "drop_duplicates"
        )

        self.duplicates_indicator = duplicates_indicator

        self.duplicates_indicator_name: Optional[str]
        if isinstance(self.duplicates_indicator, str):
            self.duplicates_indicator_name = self.duplicates_indicator
        elif isinstance(self.duplicates_indicator, bool):
            self.duplicates_indicator_name = (
                get_option("column.system.duplicates") if self.duplicates_indicator else None
            )
        else:
            raise ValueError("indicator option can only accept boolean or string arguments")

        self.merge = merge
        self.merge_suffixes = merge_suffixes
        self.prepend_levels = prepend_levels

        self._left_suffix = get_option("operators.binary.column_suffixes")[0]
        self._right_suffix = get_option("operators.binary.column_suffixes")[1]
        self._diff_days_col = get_option("column.system.diff_days")
        self._abs_diff_days_col = get_option("column.system.abs_diff_days")
        self._merge_indicator_col = get_option("column.system.merge")

        self._validate_specification()