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/3614#issuecomment-566094477,https://api.github.com/repos/pydata/xarray/issues/3614,566094477,MDEyOklzc3VlQ29tbWVudDU2NjA5NDQ3Nw==,4160723,2019-12-16T14:53:08Z,2019-12-16T14:53:08Z,MEMBER,"Autocomplete indeed works in ipython, but it doesn't seem to work for accessors in my emacs configuration (`lsp-mode` / `lsp-python-ms` / `python-language-server`). I haven't checked in VSCode / LSP. I'll investigate this later, it's likely an issue external to xarray. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,536900797 https://github.com/pydata/xarray/issues/3614#issuecomment-566089302,https://api.github.com/repos/pydata/xarray/issues/3614,566089302,MDEyOklzc3VlQ29tbWVudDU2NjA4OTMwMg==,48983334,2019-12-16T14:40:24Z,2019-12-16T14:40:24Z,CONTRIBUTOR,You are right. The autocomplete does work. I had a problem in my script.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,536900797 https://github.com/pydata/xarray/issues/3614#issuecomment-565718679,https://api.github.com/repos/pydata/xarray/issues/3614,565718679,MDEyOklzc3VlQ29tbWVudDU2NTcxODY3OQ==,14808389,2019-12-14T13:45:38Z,2019-12-14T13:54:30Z,MEMBER,"that works for me, too. I moved the accessor code into a file, then imported it: ```python In [1]: import xarray as xr ...: import numpy as np ...: import custom_accessor In [2]: ds = xr.Dataset( ...: {""a"": ((""latitude"", ""longitude""), np.linspace(0, 1, 5 * 10).reshape(5, 10))}, ...: coords={""latitude"": np.arange(5), ""longitude"": np.arange(10)}, ...: ) In [3]: # ds.geo.c ...: ds.geo.center Out[3]: (2.0, 4.5) ``` It also works with the builtin `str`, `dt` and `plot` `DataArray` accessors (just not if I'm trying to access the `DataArray`s from a `Dataset` as described above). Edit: does your accessor work, i.e. does `ds.geo.center` return something?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,536900797 https://github.com/pydata/xarray/issues/3614#issuecomment-565718085,https://api.github.com/repos/pydata/xarray/issues/3614,565718085,MDEyOklzc3VlQ29tbWVudDU2NTcxODA4NQ==,48983334,2019-12-14T13:37:06Z,2019-12-14T13:37:06Z,CONTRIBUTOR,"I can reproduce your first code perfect fine in ipython, with autocomplete. However, we're defining an accessor in ipython. It seems if an accessor is used in a module and that module imported to ipython the autocomplete doesn't work. It's like ipython can't ""see"" the functions in the accessor's class until runtime. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,536900797 https://github.com/pydata/xarray/issues/3614#issuecomment-565476562,https://api.github.com/repos/pydata/xarray/issues/3614,565476562,MDEyOklzc3VlQ29tbWVudDU2NTQ3NjU2Mg==,14808389,2019-12-13T15:11:57Z,2019-12-14T00:14:55Z,MEMBER,"This already works for me in a IPython shell (`jedi 0.15.1`, `ipython 7.9.0`): ```python In [1]: import xarray as xr ...: import numpy as np In [2]: @xr.register_dataset_accessor(""geo"") ...: class GeoAccessor: ...: def __init__(self, xarray_obj): ...: self._obj = xarray_obj ...: ...: @property ...: def center(self): ...: # return the geographic center point of this dataset ...: lon = self._obj.latitude ...: lat = self._obj.longitude ...: return (float(lon.mean()), float(lat.mean())) ...: ...: def plot(self): ...: # plot this array's data on a map, e.g., using Cartopy ...: pass ...: In [3]: ds = xr.Dataset( ...: {""a"": ((""latitude"", ""longitude""), np.linspace(0, 1, 5 * 10).reshape(5, 10))}, ...: coords={""latitude"": np.arange(5), ""longitude"": np.arange(10)}, ...: ) In [4]: # ds.geo.c: ...: ds.geo.center Out[4]: (2.0, 4.5) ``` Am I missing something? Edit: what does not work is something like ```python In [5]: ds = xr.Dataset( ...: {""a"": ((""latitude"", ""longitude""), np.linspace(0, 1, 5 * 10).reshape(5, 10))}, ...: coords={ ...: ""latitude"": np.arange(5), ...: ""longitude"": np.arange(10), ...: ""time"": np.datetime64(""1999-01-01""), ...: }, ...: ) In [6]: # ds.time.dt.y ...: ds.time.dt.y In [7]: time = ds.time ...: # time.dt.y ...: time.dt.year ``` so it's not possible to autocomplete `DataArray` accessors via `getattr` on `Dataset`.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,536900797 https://github.com/pydata/xarray/issues/3614#issuecomment-565403514,https://api.github.com/repos/pydata/xarray/issues/3614,565403514,MDEyOklzc3VlQ29tbWVudDU2NTQwMzUxNA==,4160723,2019-12-13T11:13:26Z,2019-12-13T11:13:26Z,MEMBER,"That would be great if it could work in ipython and elsewhere too (e.g., IDEs, etc.). I guess it might be worth having a look at [jedi](https://github.com/davidhalter/jedi) and see if this could be easily fixed. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,536900797