Skip to content

Commit

Permalink
DataSets can now be created directly from numpy arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
drusk committed Sep 18, 2014
1 parent 903bdb8 commit 636035b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pml/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def __init__(self, data, labels=None):
data:
Data of unknown type. The supported types are:
1) pandas DataFrame
2) Python lists or pandas DataFrame
3) an existing DataSet object
2) Python lists
3) numpy array
4) an existing DataSet object
labels: pandas Series, Python list or Python dictionary
The classification labels for the samples in data. If they are
not known (i.e. it is an unlabelled data set) the value None
Expand All @@ -67,6 +68,8 @@ def __init__(self, data, labels=None):
self._dataframe = data
elif isinstance(data, list):
self._dataframe = pd.DataFrame(data)
elif isinstance(data, np.ndarray):
self._dataframe = pd.DataFrame(data)
elif isinstance(data, DataSet):
self._dataframe = data._dataframe.copy()
else:
Expand Down
6 changes: 6 additions & 0 deletions test/test_pml/test_data/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
from test.matchers.pandas_matchers import equals_series, equals_dataframe

class DataSetTest(base_tests.BaseDataSetTest, base_tests.BaseFileLoadingTest):
def test_create_dataset_from_numpy_array(self):
as_list = [[0, 1], [2, 3]]
np_array = np.array(as_list)
dataset = DataSet(np_array)

assert_that(dataset, equals_dataset(as_list))

def test_reduce_rows(self):
dataset = DataSet([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Expand Down

0 comments on commit 636035b

Please sign in to comment.