<commit_before>''' 
    Use single-linkage hierarchical clustering to build up a tree
    of clusters from a similarity list.
        - Similarities -> Hierarchical Clustering (Tree)

    Input: Similarities - a tuple (source, target, sim)
    Output: Hierarchical Cluster (as a networkx tree datatype)
'''

import os, sys
import traceback
import json
import optparse
import networkx as nx
import collections
import matplotlib.pyplot as plt
import pandas as pd

import data_hacking.lsh_sims as lsh_sims

class HCluster():
    ''' 
        Use single-linkage hierarchical clustering to build up a tree
        of clusters from a similarity list.
            - Similarities -> Hierarchical Clustering (Tree)
    '''

    def __init__(self, records):
        ''' Init for HCluster. '''

        ''' Trying to support python list, pandas DataFrames and pandas Series. '''
        if isinstance(records, list):
            self._record_type = 'list'
            self._get_row = lambda index: self._records[index]
        elif isinstance(records, pd.DataFrame):
            self._record_type = 'dataframe'
            self._get_row = lambda index: [str(x) for x in self._records.iloc[index].values.tolist()]
        elif isinstance(records, pd.Series):
            if isinstance(records.iloc[0], list):
                self._record_type = 'series'
                self._get_row = lambda index: self._records.iloc[index]
            else:
                print 'A Series must be a series of lists'
                print 'instead got a series of %s' % type(records.iloc[0])
                exit(1)
        else:
            print 'Unknown records type for LSHSimilarities(): %s' % type(records)
            exit(1)

        # Store a handle to the records
        self._records = records

        # Other class ivars
        self.sim_method = None
        self.agg_sim = 0.0

    def set_sim_method(self, sim_function):<commit_msg>more informative comment for init method<commit_after>''' 
    Use single-linkage hierarchical clustering to build up a tree
    of clusters from a similarity list.
        - Similarities -> Hierarchical Clustering (Tree)

    Input: Similarities - a tuple (source, target, sim)
    Output: Hierarchical Cluster (as a networkx tree datatype)
'''

import os, sys
import traceback
import json
import optparse
import networkx as nx
import collections
import matplotlib.pyplot as plt
import pandas as pd

import data_hacking.lsh_sims as lsh_sims

class HCluster():
    ''' 
        Use single-linkage hierarchical clustering to build up a tree
        of clusters from a similarity list.
            - Similarities -> Hierarchical Clustering (Tree)
    '''

    def __init__(self, records):
        ''' Init for HCluster.  The records parameter can be either
            a dataframe series or a python list of features.
        '''

        ''' Trying to support python list, pandas DataFrames and pandas Series. '''
        if isinstance(records, list):
            self._record_type = 'list'
            self._get_row = lambda index: self._records[index]
        elif isinstance(records, pd.DataFrame):
            self._record_type = 'dataframe'
            self._get_row = lambda index: [str(x) for x in self._records.iloc[index].values.tolist()]
        elif isinstance(records, pd.Series):
            if isinstance(records.iloc[0], list):
                self._record_type = 'series'
                self._get_row = lambda index: self._records.iloc[index]
            else:
                print 'A Series must be a series of lists'
                print 'instead got a series of %s' % type(records.iloc[0])
                exit(1)
        else:
            print 'Unknown records type for LSHSimilarities(): %s' % type(records)
            exit(1)

        # Store a handle to the records
        self._records = records

        # Other class ivars
        self.sim_method = None
        self.agg_sim = 0.0

    def set_sim_method(self, sim_function):
{'fraction_non_alphanumeric': 0.08218145262628801, 'fraction_numerical': 0.0030158331239004774, 'mean_word_length': 2.3029045643153525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7638572', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1053, 'n_words': 379}