Skip to content

Commit

Permalink
to_castra protects list of categories
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Jul 15, 2015
1 parent 5ffaa8a commit 3c3ac7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dask/dataframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ def to_castra(self, fn=None, categories=None):
"""
from castra import Castra
name = 'to-castra' + next(tokens)
if isinstance(categories, list):
categories = (list, categories)
dsk = {name: (Castra, fn, (self._name, 0), categories)}
dsk.update(dict(((name, i), (Castra.extend, name, (self._name, i)))
for i in range(self.npartitions)))
Expand Down
13 changes: 11 additions & 2 deletions dask/dataframe/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,21 @@ def test_from_dask_array_raises():

def test_to_castra():
pytest.importorskip('castra')
df = pd.DataFrame({'x': ['a', 'b', 'c', 'D'],
df = pd.DataFrame({'x': ['a', 'b', 'c', 'd'],
'y': [1, 2, 3, 4]})
a = dd.from_pandas(df, 2)

c = a.to_castra()
assert eq(a, c[:])
try:
assert eq(a, c[:])
finally:
c.drop()

c = a.to_castra(categories=['x'])
try:
assert c[:].dtypes['x'] == 'category'
finally:
c.drop()


def test_to_hdf():
Expand Down

0 comments on commit 3c3ac7a

Please sign in to comment.