How to Get the Best Autocomplete in Jupyter Notebooks and More
Read this post in other languages:
Writing code in a “plain text”-looking Jupyter notebook, without any coding assistance, can be overwhelming and can definitely slow data scientists down. In this blog post we’ll explain 2 ways to avoid this pitfall and access autocompletion and other coding assistance features for your Jupyter notebooks.
Enable autocomplete feature
To enable code autocomplete in Jupyter Notebook or JupyterLab, you just need to hit the Tab key while writing code. Jupyter will suggest a few completion options. Navigate to the one you want with the arrow keys, and hit Enter to choose the suggestion.
Unfortunately, Jupyter doesn’t offer automatic invocation for code completion options, which means you will be pressing the Tab key all the time.
To avoid this, you can consider trying Datalore – a collaborative data science platform, which is available online for free.
Datalore will automatically invoke code completion options, and it will give you contextual help when specifying method parameters. It will also take care of small but important things like putting your caret inside the parentheses, making your code less error-prone.
A Notebook environment will already be preconfigured for you with the top data science packages preinstalled, so you can start writing code in Datalore right away.
Get proper code indentation for Python
In Python, indentation is important. Let’s take a look at how indenting works for a simple if clause.
In the example below, JupyterLab uses the wrong indentation, which leads to an error when executing the cell:
Datalore corrects the indentation automatically, ensuring your code will be executed without errors.
Get contextual help
In JupyterLab you can get contextual help by selecting a function and using the context menu. Datalore gives you contextual help when you hover over any function/method, and it also suggests method parameters on the fly while you’re typing code.
Other code editing features in Datalore
Datalore offers a wide variety of quick-fixes, such as import optimization, which helps your code look more professional and clean.
Datalore lets you rename variables and functions using the context menu. It will rename only the variables or functions, leaving text inputs with the same name unchanged. In JupyterLab, classic Find and Replace acts differently: it will replace all entries just like in a text file.
Highlighting errors before you execute the code
Nobody likes to see a red error message in a notebook. Datalore will highlight the errors before the execution of the cell, giving you a heads up about any potential problems.
SQL, R, Scala, and Kotlin code autocomplete
In addition to Python, Datalore also offers code completion and syntax highlighting for SQL, R, Scala, and Kotlin.
|Python code autocomplete||Invoked manually by pressing tab; auto-invocation available via Jupyter plugins and extensions||Invoked automatically out of the box|
|SQL, R, Scala, and Kotlin code autocomplete||⛔️||✅|
|Contextual help||In a separate tab||On hover|
|Quick-fixes (e.g. removing unused imports)||⛔️||✅|
|Refactorings (e.g. renaming variables)||⛔️||✅|
|Method specifications when typing code||⛔️||✅|
|Code indentation||Sometimes inaccurate (see examples above)||✅|
We hope these tips will help you enjoy a better code editing experience and make you more confident when sharing your work.
How to try Datalore
If you’d like to use Datalore for yourself, register online for Datalore Community or Datalore Professional. You can also try it for your team by hosting Datalore in your private cloud or on-premises with the Enterprise plans.
Happy data sciencing!
The Datalore team