Skip to content

Commit 466e51e

Browse files
committed
COMPAT: Pandas 0.21.0 type coercion
See pandas-dev/pandas#17767 and pandas-dev/pandas#16821
1 parent 47a2811 commit 466e51e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

dask/dataframe/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import absolute_import, division, print_function
22

3-
from collections import Iterator
3+
from collections import Iterator, Iterable
44
from functools import wraps, partial
55
import operator
66
from operator import getitem
@@ -206,6 +206,12 @@ def _scalar_binary(op, self, other, inv=False):
206206
return Scalar(dsk, name, meta)
207207

208208

209+
# Register Scalar with Iterable so that binops with pandas types
210+
# Go through correctly, rather than forcing object typecast
211+
# See https://github.com/pandas-dev/pandas/issues/17767
212+
Iterable.register(Scalar)
213+
214+
209215
class _Frame(Base):
210216
""" Superclass for DataFrame and Series
211217

dask/dataframe/tests/test_arithmetics_reduction.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ def test_scalar_arithmetics():
456456
assert_eq(~(l == r), ~(el == er))
457457

458458

459+
def test_scalar_arithmetics_dtypes():
460+
s = dd.core.Scalar({('s', 0): 10}, 's', 'i8')
461+
pdf = pd.DataFrame({'a': [1, 2, 3, 4, 5, 6, 7],
462+
'b': [7, 6, 5, 4, 3, 2, 1]})
463+
result = (pdf + s).dtypes
464+
expected = pdf.dtypes
465+
assert_eq(result, expected)
466+
467+
459468
def test_scalar_arithmetics_with_dask_instances():
460469
s = dd.core.Scalar({('s', 0): 10}, 's', 'i8')
461470
e = 10

0 commit comments

Comments
 (0)