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
Tab completion on DataArray instance fails in REPL when using Readline #8718
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
From https://docs.python.org/3/library/rlcompleter.html
This seems like a bug in the |
Looking at the source of Later there is a call to Example:
While I agree that the wording in the |
Possibly we could only supply
|
@max-sixty, I'm honestly new to xarray even as a user, so unfamiliar with the internals. Hence the aggressive And the initial issue is admittedly very minor: after some time and red herrings, I just thought I'd better document the root cause. Intuitively however, I'd say changing |
For sure, appreciate it!
Maaaybe. I agree it's a bit unusual to have a non-attribute error on an attribute access. We could use pd.DataFrame(np.array([0., 1.]))[0].dt
AttributeError: Can only use .dt accessor with datetimelike values ...which would also likely avoid any magic with What do others think? |
Sure, but just to clarify:
does not raise anything. Of course, if you go around accessing attributes at will, that might not be safe, and you would expect an Apparently |
Right, that's because without the default, it raises an |
Yes makes sense, |
Discussion at pydata#8718
* Switch `.dt` to raise an `AttributeError` Discussion at #8718 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Switch `.dt` to raise an `AttributeError` Discussion at pydata#8718 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
What happened?
In the standard Python REPL running on Linux, pressing
Tab
after a DataArray instance and a dot results in no completions. For example:If another character is typed after the dot, completions seem to work fine again.
This issue does not occur in IPython launched directly in the shell. (It does, and gets worse, when using IPython from Emacs: see "Anything else?" below.)
After some digging and comparing I suspect this happens specifically in REPLs using Readline, e.g. the standard Python REPL when on Linux. (IPython itself does not use Readline, running it in Emacs does by default.) When using Readline, the completions come from the
rlcompleter
module in the standard library. Trying to manually obtain the completions ofda.
from the example above results in a TypeError raised by xarray'sCombinedDatetimelikeAccessor
: see the minimal example below.What did you expect to happen?
I expected to see the attributes of the DataArray after pressing
Tab
, and I did not expect manually obtaining the completions to result in a TypeError raised by xarray.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
I found this issue by using xarray in IPython, launched from Emacs. Not seeing the completions as described above is barely a nuisance and I probably would not have noticed, but from Emacs, using the default "native completions" (i.e. Readline), pressing
Tab
freezes the editor for about five seconds, followed by no completions. The next command that is run results in aSyntaxError
, printing back the entered command with0__dum
prepended.This exacerbation is of course an Emacs issue and not an xarray issue, but I am including it here since this is how I found out in the first place, and since the root cause seems to be the xarray error above, which is not properly handled by Emacs.
For Emacs users reading this, the workaround is to disable "native completions": for the case of IPython this uses IPython's own completer directly, which seems to work fine.
Environment
INSTALLED VERSIONS
commit: None
python: 3.11.2 (main, Feb 12 2023, 16:44:30) [GCC 12.2.1 20230201]
python-bits: 64
OS: Linux
OS-release: 6.7.1-arch1-1
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.3-development
xarray: 2024.1.1
pandas: 2.0.3
numpy: 1.25.2
scipy: 1.10.1
netCDF4: 1.6.5
pydap: None
h5netcdf: 1.3.0
h5py: 3.10.0
Nio: None
zarr: None
cftime: 1.6.3
nc_time_axis: None
iris: None
bottleneck: None
dask: 2024.1.1
distributed: 2024.1.1
matplotlib: 3.7.2
cartopy: None
seaborn: 0.12.2
numbagg: None
fsspec: 2023.6.0
cupy: None
pint: None
sparse: None
flox: 0.9.0
numpy_groupies: 0.10.2
setuptools: 68.1.0
pip: 24.0
conda: None
pytest: 7.4.0
mypy: None
IPython: 8.21.0
sphinx: 7.2.6
The text was updated successfully, but these errors were encountered: