Repository: dask/dask

Issue:
test_set_index_on_empty failing on Python 3.4 and NumPy 1.10's CI
Seeing `test_set_index_on_empty` failing on `master`'s CI in the Python 3.4 and NumPy 1.10 job. The others seem to be passing fine.

<details>
<summary>Test failure:</summary>

```python
___________________________ test_set_index_on_empty ____________________________
[gw0] linux -- Python 3.4.5 /home/travis/miniconda/envs/test-environment/bin/python
    def test_set_index_on_empty():
        test_vals = [1, 2, 3, 4]
        converters = [
            int,
            float,
            str,
            lambda x: pd.to_datetime(x, unit='ns'),
        ]
    
        for converter in converters:
            df = pd.DataFrame([{'x': converter(x), 'y': x} for x in test_vals])
            ddf = dd.from_pandas(df, npartitions=4)
    
            assert ddf.npartitions > 1
    
            ddf = ddf[ddf.y > df.y.max()].set_index('x')
            expected_df = df[df.y > df.y.max()].set_index('x')
    
>           assert assert_eq(ddf, expected_df)
dask/dataframe/tests/test_shuffle.py:639: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
dask/dataframe/utils.py:563: in assert_eq
    assert_divisions(a)
dask/dataframe/utils.py:622: in assert_divisions
    results = get_sync(ddf.dask, ddf.__dask_keys__())
dask/local.py:562: in get_sync
    return get_async(apply_sync, 1, dsk, keys, **kwargs)
dask/local.py:529: in get_async
    fire_task()
dask/local.py:504: in fire_task
    callback=queue.put)
dask/local.py:551: in apply_sync
    res = func(*args, **kwds)
dask/local.py:295: in execute_task
    result = pack_exception(e, dumps)
dask/local.py:290: in execute_task
    result = _execute_task(task, data)
dask/local.py:271: in _execute_task
    return func(*args2)
dask/dataframe/core.py:3226: in apply_and_enforce
    df = func(*args, **kwargs)
dask/dataframe/shuffle.py:418: in set_partitions_pre
    partitions = pd.Series(divisions).searchsorted(s, side='right') - 1
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = 0   NaN
1   NaN
dtype: float64
v = Series([], Name: x, dtype: datetime64[ns]), side = 'right', sorter = None
    @Substitution(klass='Series', value='v')
    @Appender(base._shared_docs['searchsorted'])
    def searchsorted(self, v, side='left', sorter=None):
        if sorter is not None:
            sorter = _ensure_platform_int(sorter)
        return self._values.searchsorted(Series(v)._values,
>                                        side=side, sorter=sorter)
E       TypeError: invalid type promotion
../../../miniconda/envs/test-environment/lib/python3.4/site-packages/pandas/core/series.py:1523: TypeError
```

</details>

<br>

ref: https://travis-ci.org/dask/dask/jobs/296796310#L7842


Discussion:

Resolving patch:
diff --git a/dask/dataframe/partitionquantiles.py b/dask/dataframe/partitionquantiles.py
--- a/dask/dataframe/partitionquantiles.py
+++ b/dask/dataframe/partitionquantiles.py
@@ -310,11 +310,11 @@ def process_val_weights(vals_and_weights, npartitions, dtype_info):
     dtype, info = dtype_info
 
     if not vals_and_weights:
-        if not (np.can_cast(np.nan, dtype) or np.can_cast(np.datetime64('NaT'), dtype)):
+        try:
+            return np.array(None, dtype=dtype)
+        except Exception:
             # dtype does not support None value so allow it to change
-            dtype = np.dtype(None)
-
-        return np.array(None, dtype=dtype)
+            return np.array(None, dtype=np.float_)
 
     vals, weights = vals_and_weights
     vals = np.array(vals)


Test patch: