Skip to content

Commit

Permalink
Merge pull request jma127#9 from stiebels/master
Browse files Browse the repository at this point in the history
debugged function call _load_file in convert function
  • Loading branch information
jma127 authored Oct 21, 2017
2 parents 686c62e + b1d7451 commit b13d330
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pyltr/data/pandas_converter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#%%
import pandas as pd


Expand All @@ -10,18 +11,23 @@ class PandasLetorConverter(object):
def __init__(self, path):
'''
Arguments:
path: path to letor txt file
path (str): path to letor txt file
'''
self._path = path
self.path = path


@property
def path(self):
return self._path


@path.setter
def path(self, p):
if type(p) is not str:
raise TypeError('path must be of type str')
self._path = p


def _load_file(self):
'''
Loads and parses raw letor txt file.
Expand All @@ -31,6 +37,7 @@ def _load_file(self):
'''
return pd.read_csv(str(self._path), sep=" ", header=None)


def _drop_col(self, df):
'''
Drops last column, which was added in the parsing procedure due to a
Expand All @@ -43,6 +50,7 @@ def _drop_col(self, df):
'''
return df.drop(df.columns[-1], axis=1)


def _split_colon(self, df):
'''
Splits the data on the colon and transforms it into a tabular format
Expand All @@ -59,13 +67,14 @@ def _split_colon(self, df):
df.columns = ['rel', 'qid'] + [str(x) for x in range(1,len(df.columns)-1)] # renaming cols
return df


def convert(self):
'''
Performs final conversion.
Return:
fully converted pandas dataframe
'''
df_raw = self._load_file(self._path)
df_raw = self._load_file()
df_drop = self._drop_col(df_raw)
return self._split_colon(df_drop)

0 comments on commit b13d330

Please sign in to comment.