Skip to content

Commit

Permalink
COMPAT: Pandas 0.21.0 type coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Oct 3, 2017
1 parent 47a2811 commit 466e51e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dask/dataframe/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division, print_function

from collections import Iterator
from collections import Iterator, Iterable
from functools import wraps, partial
import operator
from operator import getitem
Expand Down Expand Up @@ -206,6 +206,12 @@ def _scalar_binary(op, self, other, inv=False):
return Scalar(dsk, name, meta)


# Register Scalar with Iterable so that binops with pandas types
# Go through correctly, rather than forcing object typecast
# See https://github.com/pandas-dev/pandas/issues/17767
Iterable.register(Scalar)


class _Frame(Base):
""" Superclass for DataFrame and Series
Expand Down
9 changes: 9 additions & 0 deletions dask/dataframe/tests/test_arithmetics_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ def test_scalar_arithmetics():
assert_eq(~(l == r), ~(el == er))


def test_scalar_arithmetics_dtypes():
s = dd.core.Scalar({('s', 0): 10}, 's', 'i8')
pdf = pd.DataFrame({'a': [1, 2, 3, 4, 5, 6, 7],
'b': [7, 6, 5, 4, 3, 2, 1]})
result = (pdf + s).dtypes
expected = pdf.dtypes
assert_eq(result, expected)


def test_scalar_arithmetics_with_dask_instances():
s = dd.core.Scalar({('s', 0): 10}, 's', 'i8')
e = 10
Expand Down

0 comments on commit 466e51e

Please sign in to comment.