<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Built-in modules #

# First party modules #

# Third party modules #
import pandas

# Internal modules #

###############################################################################
def flexible_join(first, other, on, how=None, lsuffix='', rsuffix=''):
    """
    Implement a common join pattern with pandas set_index()
    on both data frames followed by a reset_index() at the end.
    """
    # Check if `on` is a set #
    if isinstance(on, set): on = list(on)
    # Set indexes #
    first  = first.set_index(on)
    other  = other.set_index(on)
    # TODO check the data types (dtypes) of all the index columns
    #  are matching on both sides of the join.
    result = first.join(other, how=how, lsuffix=lsuffix, rsuffix=rsuffix)
    result = result.reset_index()
    # Return #
    return result

###############################################################################
def left_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='left')

def right_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='right')

def inner_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='inner')

def outer_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='outer')

###############################################################################
# Add a nice method to pandas.DataFrame objects #
pandas.DataFrame.left_join  = left_join
pandas.DataFrame.right_join = right_join
pandas.DataFrame.inner_join = inner_join
pandas.DataFrame.outer_join = outer_join

<commit_msg>Wrong default parameters in pandas flexible join function<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Built-in modules #

# First party modules #

# Third party modules #
import pandas

# Internal modules #

###############################################################################
def flexible_join(first, other, on, how=None, lsuffix=None, rsuffix=None):
    """
    Implement a common join pattern with pandas set_index()
    on both data frames followed by a reset_index() at the end.
    """
    # Check if `on` is a set #
    if isinstance(on, set): on = list(on)
    # Set indexes #
    first  = first.set_index(on)
    other  = other.set_index(on)
    # TODO check the data types (dtypes) of all the index columns
    #  are matching on both sides of the join.
    result = first.join(other, how=how, lsuffix=lsuffix, rsuffix=rsuffix)
    result = result.reset_index()
    # Return #
    return result

###############################################################################
def left_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='left')

def right_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='right')

def inner_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='inner')

def outer_join(*args, **kwargs):
    """This method is patched onto pandas.DataFrame for convenience."""
    return flexible_join(*args, **kwargs, how='outer')

###############################################################################
# Add a nice method to pandas.DataFrame objects #
pandas.DataFrame.left_join  = left_join
pandas.DataFrame.right_join = right_join
pandas.DataFrame.inner_join = inner_join
pandas.DataFrame.outer_join = outer_join


{'fraction_non_alphanumeric': 0.23029045643153526, 'fraction_numerical': 0.001037344398340249, 'mean_word_length': 4.655425219941349, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3191890', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1057, 'n_words': 333}