Skip to content

isin issue with numpy 1.12 on Python 2 #3388

Closed

Description

@mrocklin

I received the following report on da.isin through a side channel. cc @jakirkham

We're using numpy 1.12, which doesn't have numpy.isin(). #3363 leads to:

% python -c 'import dask.array'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "dask/array/__init__.py", line 8, in <module>
    from .routines import (take, choose, argwhere, where, coarsen, insert,
  File "dask/array/routines.py", line 790, in <module>
    def isin(element, test_elements, assume_unique=False, invert=False):
  File "/opt/python/python-2.7/lib64/python2.7/functools.py", line 33, in update_wrapper
    setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'NoneType' object has no attribute '__module__'

where wrapped is None and attr is '__module__'.

I think this only happens with Python 2's functools.

py3: https://github.com/python/cpython/blame/0f914b5b5f6ba186afd7112fc851c97247076f70/Lib/functools.py#L52
py2: https://github.com/python/cpython/blame/77f0a41d72886513f5e9277e5587455745c29ac1/Lib/functools.py#L32

Activity

  1. jakirkham commented on Apr 10, 2018

    @jakirkham
    Member

    Interesting, thanks for the info. Also cc @shoyer.

  2. jakirkham commented on Apr 10, 2018

    @jakirkham
    Member

    This reminds of a more general discussion about how we document API ( #3265 ) that we should have at some point. ;)

    As to the particular problem, we have a few options. None particularly difficult (some are easier though).

    1. Only define Dask Array isin for versions of NumPy that have it.
    2. Vendor a copy of NumPy's isin implementation and use it.
    3. Implement isin with in1d + reshape and copy/rewrite the docstring from NumPy.
    4. Vendor/implement our own wraps (combined with part of 3).
    5. Something else?

    Thoughts?

  3. shoyer commented on Apr 10, 2018

    @shoyer
    Member

    Oops. I thought all we would miss here is the docstring on old versions of NumPy, but it looks like that causes a crash at import time :(.

    @wraps(getattr(np, 'isin', np.1nd)) would probably be an adequate work-around for now.

    I didn't bother to vender a copy of numpy's isin because it was just as easy to write dask's isin in terms of np.in1d.

  4. jakirkham commented on Apr 10, 2018

    @jakirkham
    Member

    Yeah, I thought the Python 3, NumPy 1.12 and NumPy 1.10 CI combinations were sufficient to rule out this sort of issue, but guess not. Easily fixable though. So wouldn't stress about it.

    That's probably ok. It's a little confusing based on the return type, but expect users can figure this out. Also it is no worse than many of the other docstrings using this same strategy.

    Ultimately we should discuss how to fix the docstrings to be clearer at some point, but the discussion need not happen now in this issue. Just should happen eventually with this just highlighting another pain point.

    That's right. Forgot we were already using in1d. Edited the list in my original comment accordingly.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions