Skip to content

Commit 9e7abea

Browse files
committed
for pandas DataFrame
1 parent cd1f987 commit 9e7abea

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

densratio/helpers.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def to_numpy_matrix(x):
1313
return matrix(x).T
1414
else:
1515
return matrix(x)
16+
elif str(type(x)) == "<class 'pandas.core.frame.DataFrame'>":
17+
return x.as_matrix()
1618
elif not x:
1719
raise ValueError("Cannot transform to numpy.matrix.")
1820
else:

tests/test_helpers.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from numpy import array, matrix
66
from numpy.testing import assert_array_equal
7+
from pandas import DataFrame
78
from .context import helpers
89

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

46+
def test_to_numpy_matrix_pandas_DataFrame(self):
47+
x = DataFrame([[1,2],[3,4]])
48+
x = helpers.to_numpy_matrix(x)
49+
assert_array_equal(x, matrix([[1,2],[3,4]]))
4550

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

0 commit comments

Comments
 (0)