Skip to content

ENH: Add comparison operations to Index #2195

Closed

Description

@TomAugspurger

As part of #2190 we'll need something like df.index > pd.Timestamp('2016-01-01'), which hasn't been implemented yet.

In [3]: import dask.dataframe as dd

In [4]: import pandas as pd

In [5]: s = dd.from_pandas(pd.Series(range(10)), 2)

In [6]: s.index > 5
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-86de14943cf2> in <module>()
----> 1 s.index > 5

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/dataframe/core.py in <lambda>(self, other)
    968             return lambda self, other: elemwise(op, other, self)
    969         else:
--> 970             return lambda self, other: elemwise(op, self, other)
    971
    972     def rolling(self, window, min_periods=None, freq=None, center=False,

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/dataframe/core.py in elemwise(op, *args, **kwargs)
   2819         meta = _emulate(op, *args, **kwargs)
   2820
-> 2821     return new_dd_object(dsk, _name, meta, divisions)
   2822
   2823

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/dataframe/core.py in new_dd_object(dsk, _name, meta, divisions)
     77     Decides the appropriate output class based on the type of `meta` provided.
     78     """
---> 79     return _get_return_type(meta)(dsk, _name, meta, divisions)
     80
     81

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/dataframe/core.py in __init__(self, dsk, name, meta, divisions)
    101         self.dask = dsk
    102         self._name = name
--> 103         meta = make_meta(meta)
    104         if isinstance(meta, (pd.DataFrame, pd.Series, pd.Index)):
    105             raise TypeError("Expected meta to specify scalar, got "

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/dataframe/utils.py in make_meta(x, index)
    304         return _nonempty_scalar(x)
    305
--> 306     raise TypeError("Don't know how to create metadata from {0}".format(x))
    307
    308

TypeError: Don't know how to create metadata from [False False]

This isn't completely trivial, since pandas.Index comparisons return an array instead of an Index, so I've split it off into a separate issue.

Activity

  1. mrocklin commented on Apr 10, 2017

    @mrocklin
    Member

    I think it is reasonable to break with Pandas here. We do this for other operations that return numpy arrays.

  2. jcrist commented on Apr 10, 2017

    @jcrist
    Member

    We do this for other operations that return numpy arrays.

    Related comment: #1877 (comment) and responses afterwards. I think this is a good solution, and apparently one pandas is moving towards as well.

  3. mrocklin commented on Oct 23, 2018

    @mrocklin
    Member

    Seems to work ok today

    In [1]: In [3]: import dask.dataframe as dd
       ...: 
       ...: In [4]: import pandas as pd
       ...: 
       ...: In [5]: s = dd.from_pandas(pd.Series(range(10)), 2)
       ...: 
       ...: In [6]: s.index > 5
       ...: 
    Out[1]: dask.array<gt, shape=(nan,), dtype=bool, chunksize=(nan,)>
    
    In [2]: _.compute()
    Out[2]: 
    array([False, False, False, False, False, False,  True,  True,  True,
            True])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions