home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 922942743

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2511#issuecomment-922942743 https://api.github.com/repos/pydata/xarray/issues/2511 922942743 IC_kwDOAMm_X843Av0X 16700639 2021-09-20T13:45:56Z 2021-09-20T13:45:56Z CONTRIBUTOR

I wrote a very naive fix, it works but seems to perform really slowly, I would appreciate some feedback (I'm a beginner with Dask). Basically, I added k = dask.array.asarray(k, dtype=np.int64) to do the exact same thing as with numpy. I can create a PR if it's better to review this

The patch: ``` class VectorizedIndexer(ExplicitIndexer): """Tuple for vectorized indexing.

All elements should be slice or N-dimensional np.ndarray objects with an
integer dtype and the same number of dimensions. Indexing follows proposed
rules for np.ndarray.vindex, which matches NumPy's advanced indexing rules
(including broadcasting) except sliced axes are always moved to the end:
https://github.com/numpy/numpy/pull/6256
"""

__slots__ = ()

def __init__(self, key):
    if not isinstance(key, tuple):
        raise TypeError(f"key must be a tuple: {key!r}")

    new_key = []
    ndim = None
    for k in key:
        if isinstance(k, slice):
            k = as_integer_slice(k)
        elif isinstance(k, np.ndarray) or isinstance(k, dask.array.Array):
            if not np.issubdtype(k.dtype, np.integer):
                raise TypeError(
                    f"invalid indexer array, does not have integer dtype: {k!r}"
                )
            if ndim is None:
                ndim = k.ndim
            elif ndim != k.ndim:
                ndims = [k.ndim for k in key if isinstance(k, np.ndarray)]
                raise ValueError(
                    "invalid indexer key: ndarray arguments "
                    f"have different numbers of dimensions: {ndims}"
                )
            if isinstance(k, dask.array.Array):
                k = dask.array.asarray(k, dtype=np.int64)
            else:
                k = np.asarray(k, dtype=np.int64)
        else:
            raise TypeError(
                f"unexpected indexer type for {type(self).__name__}: {k!r}"
            )
        new_key.append(k)

    super().__init__(new_key)

```

{
    "total_count": 2,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 2,
    "eyes": 0
}
  374025325
Powered by Datasette · Queries took 0.658ms · About: xarray-datasette