17

I am using VScode and the interaction mode to interactively write a python script. Is there any way to get autocompletion for pandas column names, ideally within the editor or the interactive window. Currently any of those is working.

I only could find this related post which was closed without resolving the problem: https://github.com/microsoft/vscode-jupyter/issues/1561

I also tried rolling back to the old implementation of the interactive mode as suggested here: https://github.com/microsoft/vscode-jupyter/issues/6995 but this did not work as well.

Any suggestions to resolve this issue are welcome as all the rest of VSCode seems to be pretty awesome.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
FAMG
  • 395
  • 1
  • 9
  • I still could not find a solution to the problem. Hence, any help is highly appreciated. – FAMG Feb 23 '23 at 09:23
  • In Jupyter interactive mode, it should "just work" now after [10137](https://github.com/microsoft/vscode-jupyter/pull/10137) (released [7 June 2022](https://github.com/microsoft/vscode-jupyter/blob/main/CHANGELOG.md#20225100-7-june-2022)), though you'll probably have to start typing the column name first. What happens exactly when you try it? Note that 10137 only affects strings (i.e. bracket notation, `df['x']`); it should have worked already for dot notation (i.e. `df.x`). – wjandrea Apr 17 '23 at 17:49

1 Answers1

4

This question led me down a rabbit hole!

I had never really realized that this was a problem since I am normally using jupyter notebooks. Anyways, a new thread about this topic was started at here! The thread ended up in this PR where they have added a new config parameter "jupyter.enableExtendedKernelCompletions". You can find that setting by going to settings and typing "jupyter" in the search bar. CAUTION: As @wjandrea pointed out in comments, this setting is only changing the module used by the kernel to check for autocompletes instead of the Jupyter server and is linked to some kernel problems when working with large data sets.

jupyter.enableExtendedKernelCompletions

This setting was not necessary for me, as I had autocomplete in the interactive window already, with it turned off. But it might do something for you.

Screenshot of pylance in Editor

So I started to look into why autocompletion for column names in *.py files is still not supported, and investigate if there are any alternatives. AI code helpers seem to understand what column names are present through static code analysis, such as Tabnine.

Tabnine code helper

This might be overkill for such a trivial use case though. It also doesn't help that it costs $12 per month.

Spyder is an alternative to VSCode. It is however made for Python, which might not be what you are after.

Spyder IDE

Dictionary keys are supported through static code analysis but do not know the state of the dictionary.

Dict auto complete

The whole process boils down to that when the DataFrame is created in a cell it becomes accessible to the jupyter server, which can keep track of the column names, values etc. Before this is done the interpreter does not know what is in the object, it just knows it's a Pandas.DataFrame. Therefore I can't see column names completion being done anytime soon in *.py files (without AI companions).

No code completion for loaded files

TL;DR: Column name completion is available in the interactive window, but will probably not be available in pure python files anytime soon.

Hope gave some insight :)

Oddaspa
  • 731
  • 5
  • 21
  • 1
    If I'm understanding correctly, the setting `jupyter.enableExtendedKernelCompletions` just makes it so that completions in the interactive window come from the kernel instead of the language server. The language server can provide column name suggestions itself, it's just not ideal sometimes. So that setting definitely does not need to be enabled. – wjandrea Apr 15 '23 at 18:21
  • Thank you for shedding some light on the `jupyter.enableExtendedKernelCompletions` feature. I could not find much infomation on it when I tried it out. I did some more investigation after your comment and it seems like Jedi is linked to problems when used with large data sets (ref: https://stackoverflow.com/questions/44186370/kernel-taking-too-long-to-autocomplete-tab-in-jupyter-notebook). I agree with @wjandrea. No need to enable the setting. – Oddaspa Apr 17 '23 at 07:24
  • 1
    I see you updated the answer, but the details aren't right. The IPython kernel is running **on** the Jupyter server; I was actually talking about the *language* server, which is running in VSCode. However, I was wrong; reading [10137](https://github.com/microsoft/vscode-jupyter/pull/10137) again, the language server doesn't provide completions in the interactive window, IPython does -- whether or not it's using Jedi. What the setting *actually* does is enable Jedi for more precise suggestions from IPython. (Wow that's confusing.) – wjandrea Apr 17 '23 at 18:02
  • But still, the setting doesn't *need* to be enabled. – wjandrea Apr 17 '23 at 18:07
  • Thank you so much @Oddaspa for shedding some light on the current status! Still having my fingers crossed that auto completion will also come for .py files. – FAMG May 04 '23 at 16:14