Module ranky.utilities

Expand source code
#################################
########## UTILITIES ############
#################################

import pandas as pd
import numpy as np

def str_to_float(s):
    """ Convert str to float specifically to read Codalab's CSV leaderboard.

        e.g. '0.78 (2)' -> 0.78
        TODO: more robust
    """
    if isinstance(s, str):
        if s[-1]==')':
            s = float(s.split(' ')[0])
    return s

def read_codalab_csv(csv_file):
    """ Read a leaderboard generated by Codalab as a CSV file.

    Args:
        csv_file: The leaderboard downloaded from Codalab.
    """
    m = pd.read_csv(csv_file, usecols=np.arange(0,5), index_col=1)
    m = m.drop('submission_pk', axis=1)
    m = m.applymap(str_to_float)
    return m

Functions

def read_codalab_csv(csv_file)

Read a leaderboard generated by Codalab as a CSV file.

Args

csv_file
The leaderboard downloaded from Codalab.
Expand source code
def read_codalab_csv(csv_file):
    """ Read a leaderboard generated by Codalab as a CSV file.

    Args:
        csv_file: The leaderboard downloaded from Codalab.
    """
    m = pd.read_csv(csv_file, usecols=np.arange(0,5), index_col=1)
    m = m.drop('submission_pk', axis=1)
    m = m.applymap(str_to_float)
    return m
def str_to_float(s)

Convert str to float specifically to read Codalab's CSV leaderboard.

e.g. '0.78 (2)' -> 0.78 TODO: more robust

Expand source code
def str_to_float(s):
    """ Convert str to float specifically to read Codalab's CSV leaderboard.

        e.g. '0.78 (2)' -> 0.78
        TODO: more robust
    """
    if isinstance(s, str):
        if s[-1]==')':
            s = float(s.split(' ')[0])
    return s