Search code examples
pythonpandasjupyter-notebookmethod-chaining

Autocompletion in a Jupyter Notebook when chaining methods


In a Python 3 Jupyter Notebook the TAB autocompletion feature works only for the first method called on an object. For all subsequent method the TAB key is not working. I often use methods chaining and therefore the autocompletion doesn't work most of time for me.

I tried to install nbextensions and played a little with Hinterland but apparently it's not helpfull with my problem

For example:

import pandas as pd

df_ex = pd.DataFrame({
    "City": ['Cincinati', 'Milwaukee', 'Philadelphie', 'Chicago', 'Phoenix'],
    "Size": [500.15, 600.25, 700.50, 800.05, 900.9],
    "Score": [10, 20, 30, 40, 50]})

df_ex.get_dtype_counts().sum()

Here the TAB autocompletion will work only for the get_dtype_counts() method but will not work for the sum() method

As a Python beginner, autocompletion is also usefull for me to know what are all the methods that can be called at a certain point. Is there a way to make the autocompletion work or at least to get the list of the methods (and attributes) that I can call after I already called a first method on an object.


Solution

  • I have just found an advice that the source of the problem can be ipython and it should be upgraded.

    From the command prompt I run: pip install --upgrade ipython and it reported the following upgrades:

    • ipython - from 6.5.0 to 7.4.0,
    • prompt-toolkit - from 1.0.15 to 2.0.9.

    Then I restarted the Jupyter, tried your example and the Tab-completion works, also for the chained method (at least on my computer).

    Before it didn't, so apparently this upgrade helped.