-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_files.py
36 lines (32 loc) · 1.4 KB
/
load_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import joblib
def load_dataset(filename, data_path='02_data', *args, **kwargs):
try:
file = pd.read_csv(data_path + '/' + filename, *args, **kwargs)
except FileNotFoundError:
try:
file = pd.read_csv('../' + data_path + '/' + filename,
*args, **kwargs)
except FileNotFoundError:
try:
file = pd.read_pickle('data_files/' + filename.replace('.csv', '.bz2'))
except FileNotFoundError:
try:
file = pd.read_pickle('../data_files/' + filename.replace('.csv', '.bz2'))
except FileNotFoundError:
raise FileNotFoundError('{} not found in {} dir.'.format(filename,
data_path))
return file
def load_model(filename, data_path='model', *args, **kwargs):
try:
model = joblib.load(data_path + '/' + filename, *args, **kwargs)
except FileNotFoundError:
try:
model = joblib.load('../' + data_path + '/' + filename,
*args, **kwargs)
except FileNotFoundError:
raise FileNotFoundError('{} not found in {} dir.'.format(filename,
data_path))
return model