Skip to content

Commit

Permalink
Add test for missing data when converting from a list of dicts to a n…
Browse files Browse the repository at this point in the history
…umpy recarray
  • Loading branch information
cpcloud committed Jun 20, 2015
1 parent d66bc38 commit bcbbb1a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions odo/tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ def test_list_to_numpy_on_dicts():
assert convert(list, x) == [('Alice', 100), ('Bob', 200)]


def test_list_of_dicts_with_missing_to_numpy():
data = [{'name': 'Alice', 'amount': 100},
{'name': 'Bob'},
{'amount': 200}]
result = convert(np.ndarray, data)
assert result.dtype.names == ('amount', 'name')
expected = np.array([(100.0, 'Alice'),
(np.nan, 'Bob'),
(200.0, None)],
dtype=[('amount', 'float64'), ('name', 'O')])
assert np.all((result == expected) |
((result != result) & (expected != expected)))


def test_chunks_numpy_pandas():
x = np.array([('Alice', 100), ('Bob', 200)],
dtype=[('name', 'S7'), ('amount', 'i4')])
Expand Down

0 comments on commit bcbbb1a

Please sign in to comment.