Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: kind kwarg in _maybe_cast_slice_bound #41378

Merged
merged 2 commits into from
May 10, 2021

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

When I tried just removing it that broke some dask tests.

@jbrockmendel jbrockmendel added Deprecate Functionality to remove in pandas Indexing Related to indexing on series/frames, not to indexes themselves labels May 9, 2021
@jreback jreback added this to the 1.3 milestone May 10, 2021
@jreback jreback merged commit 15dff11 into pandas-dev:master May 10, 2021
@jreback
Copy link
Contributor

jreback commented May 10, 2021

sure

@@ -3685,7 +3685,7 @@ def is_int(v):
)
indexer = key
else:
indexer = self.slice_indexer(start, stop, step, kind=kind)
indexer = self.slice_indexer(start, stop, step)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, would this change possibly introduce this regression (we have pandas-1.3.0)?

14:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/pandas/core/indexes/base.py in slice_indexer(self, start, end, step, kind)
14:18:02     5684         slice(1, 3, None)
14:18:02     5685         """
14:18:02  -> 5686         start_slice, end_slice = self.slice_locs(start, end, step=step)
14:18:02     5687 
14:18:02     5688         # return a slice
14:18:02  
14:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/pandas/core/indexes/base.py in slice_locs(self, start, end, step, kind)
14:18:02     5886         start_slice = None
14:18:02     5887         if start is not None:
14:18:02  -> 5888             start_slice = self.get_slice_bound(start, "left")
14:18:02     5889         if start_slice is None:
14:18:02     5890             start_slice = 0
14:18:02  
14:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
14:18:02     5796         # For datetime indices label may be a string that has to be converted
14:18:02     5797         # to datetime boundary according to its resolution.
14:18:02  -> 5798         label = self._maybe_cast_slice_bound(label, side)
14:18:02     5799 
14:18:02     5800         # we need to look up the label
14:18:02  
14:18:02  TypeError: _maybe_cast_slice_bound() missing 1 required positional argument: 'kind'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that traceback is produced using 1.3.0? 'kind' is a keyword argument with a default value, so i dont see how that traceback could be produced

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel yes it is pandas-1.3.0 from our docker image https://hub.docker.com/repository/docker/pavics/workflow-tests tag preview.

$ docker run -it --rm --entrypoint bash pavics/workflow-tests:preview

$ conda init bash
$ bash
$ conda activate birdy
$ conda env export |grep pandas
  - geopandas=0.9.0=pyhd8ed1ab_1  
  - geopandas-base=0.9.0=pyhd8ed1ab_1                      
  - intake-geopandas=0.2.4=pyhd8ed1ab_0                                
  - pandas=1.3.0=py37h219a48f_0

This is the full error from our notebook https://github.com/bird-house/finch/blob/0346b3aa5096b88ef5bf03339a8c67ca7e4d6fdd/docs/source/notebooks/dap_subset.ipynb

18:18:02  _________ finch-master/docs/source/notebooks/dap_subset.ipynb::Cell 2 __________
18:18:02  Notebook cell execution failed
18:18:02  Cell 2: Cell execution caused an exception
18:18:02  
18:18:02  Input:
18:18:02  #NBVAL_IGNORE_OUTPUT
18:18:02  # Use the `remap_label_indexers` function to convert coordinates to *positional* indexes.
18:18:02  import datetime as dt
18:18:02  coords = dict(lat=45, lon=290)
18:18:02  index, _ = xr.core.coordinates.remap_label_indexers(ds, coords, method="nearest")
18:18:02  
18:18:02  # The `nearest` method cannot be used with slices, so we do another call for the time period.
18:18:02  ti, _ = xr.core.coordinates.remap_label_indexers(ds, dict(time=slice("2060-01-01", "2064-12-30")))
18:18:02  
18:18:02  # Merge the spatial and temporal indices
18:18:02  index.update(ti)
18:18:02  index
18:18:02  
18:18:02  Traceback:
18:18:02  
18:18:02  ---------------------------------------------------------------------------
18:18:02  TypeError                                 Traceback (most recent call last)
18:18:02  <ipython-input-3-d0a5be34f657> in <module>
18:18:02        6 
18:18:02        7 # The `nearest` method cannot be used with slices, so we do another call for the time period.
18:18:02  ----> 8 ti, _ = xr.core.coordinates.remap_label_indexers(ds, dict(time=slice("2060-01-01", "2064-12-30")))
18:18:02        9 
18:18:02       10 # Merge the spatial and temporal indices
18:18:02  
18:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/xarray/core/coordinates.py in remap_label_indexers(obj, indexers, method, tolerance, **indexers_kwargs)
18:18:02      420 
18:18:02      421     pos_indexers, new_indexes = indexing.remap_label_indexers(
18:18:02  --> 422         obj, v_indexers, method=method, tolerance=tolerance
18:18:02      423     )
18:18:02      424     # attach indexer's coordinate to pos_indexers
18:18:02  
18:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance)
18:18:02      272             coords_dtype = data_obj.coords[dim].dtype
18:18:02      273             label = maybe_cast_to_coords_dtype(label, coords_dtype)
18:18:02  --> 274             idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
18:18:02      275             pos_indexers[dim] = idxr
18:18:02      276             if new_idx is not None:
18:18:02  
18:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/xarray/core/indexing.py in convert_label_indexer(index, label, index_name, method, tolerance)
18:18:02      122             _sanitize_slice_element(label.start),
18:18:02      123             _sanitize_slice_element(label.stop),
18:18:02  --> 124             _sanitize_slice_element(label.step),
18:18:02      125         )
18:18:02      126         if not isinstance(indexer, slice):
18:18:02  
18:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/pandas/core/indexes/base.py in slice_indexer(self, start, end, step, kind)
18:18:02     5684         slice(1, 3, None)
18:18:02     5685         """
18:18:02  -> 5686         start_slice, end_slice = self.slice_locs(start, end, step=step)
18:18:02     5687 
18:18:02     5688         # return a slice
18:18:02  
18:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/pandas/core/indexes/base.py in slice_locs(self, start, end, step, kind)
18:18:02     5886         start_slice = None
18:18:02     5887         if start is not None:
18:18:02  -> 5888             start_slice = self.get_slice_bound(start, "left")
18:18:02     5889         if start_slice is None:
18:18:02     5890             start_slice = 0
18:18:02  
18:18:02  /opt/conda/envs/birdy/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
18:18:02     5796         # For datetime indices label may be a string that has to be converted
18:18:02     5797         # to datetime boundary according to its resolution.
18:18:02  -> 5798         label = self._maybe_cast_slice_bound(label, side)
18:18:02     5799 
18:18:02     5800         # we need to look up the label
18:18:02  
18:18:02  TypeError: _maybe_cast_slice_bound() missing 1 required positional argument: 'kind'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of Index do you have here? maybe its a custom subclass that overrides _maybe_cast_slice_bound and has kind as a positional argument? All of our Index subclasses have kind as a keyword argument

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of Index do you have here? maybe its a custom subclass that overrides _maybe_cast_slice_bound and has kind as a positional argument? All of our Index subclasses have kind as a keyword argument

You are right, xarray has an override !

$ grep -R  _maybe_cast_slice_bound . | grep def
./lib/python3.7/site-packages/xarray/coding/cftimeindex.py:    def _maybe_cast_slice_bound(self, label, side, kind):

And they seem to already made the matching change as well pydata/xarray#5359 but did not cut a release containing the change yet !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants