Skip to content

Commit

Permalink
for pandas DataFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxo-m committed Dec 11, 2016
1 parent cd1f987 commit 9e7abea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions densratio/helpers.py
Expand Up @@ -13,6 +13,8 @@ def to_numpy_matrix(x):
return matrix(x).T
else:
return matrix(x)
elif str(type(x)) == "<class 'pandas.core.frame.DataFrame'>":
return x.as_matrix()
elif not x:
raise ValueError("Cannot transform to numpy.matrix.")
else:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_helpers.py
Expand Up @@ -4,6 +4,7 @@

from numpy import array, matrix
from numpy.testing import assert_array_equal
from pandas import DataFrame
from .context import helpers

class BasicTestSuite(unittest.TestCase):
Expand Down Expand Up @@ -42,6 +43,10 @@ def test_to_numpy_matrix_matrix(self):
x = helpers.to_numpy_matrix(x)
assert_array_equal(x, matrix([[1,2],[3,4]]))

def test_to_numpy_matrix_pandas_DataFrame(self):
x = DataFrame([[1,2],[3,4]])
x = helpers.to_numpy_matrix(x)
assert_array_equal(x, matrix([[1,2],[3,4]]))

if __name__ == '__main__':
unittest.main()

0 comments on commit 9e7abea

Please sign in to comment.