Introducing Upgrades to Databricks Notebooks - New Editor, Python Formatting, and More
Databricks Notebooks offers a simple, unified environment for anyone building Data and AI products. Today we are excited to introduce updates to the Notebooks experience:
- New editor with faster autocomplete, improved syntax highlighting, code collapsing and more to help you code faster
- Python Code Formatter using Black to make code easier to read and review
- Run Selected Text inside Notebooks to accelerate debugging
New notebook editor
Our new editor enables many features for users that make coding easier, faster, and less error-prone. We want you to be able to seamlessly move from the IDE to the browser and have access to a similar user experience. We have adopted Monaco, the open source editor that powers Microsoft's VS Code to make your life easier.
Autocomplete-as-you-type
Previously you needed to manually activate the autocomplete suggestion box by hitting Shift+Tab. Now, with the new editor, the autocomplete suggestion box will appear automatically as you type.
The autocomplete function not only works for symbols like Python methods and attributes, but it will also provide table and column names in SQL statements. It also recognizes and adds Databricks SQL functions from the tokenizer. This lets you reduce errors and grab the right object the first time.
Parameter hints
Get a helpful reminder of the function call arguments with inline parameter hints.
Mac: Shift-Cmd-Space
Windows: Ctrl-Shift-Space
Docstrings on hover
You can now hover over types and functions in your code to display the docstrings.
Syntax highlighting
Having properly highlighted code makes coding, editing, and troubleshooting much faster. In the Monaco editor, we do a better job highlighting the tokens in your code cells.
Code collapsing
Code folding lets you temporarily hide sections of code. This can be helpful when working with long code blocks because it lets you focus on specific sections of code you are working on.
Multiple cursors
You can add multiple cursors for fast, simultaneous edits. This common shortcut makes editing easier when you have a series of similar inputs and want to change them together. You can add additional cursors with Alt-click in the editor window or by pressing ⌥⌘↓ or ⌥⌘↑ on Macs or Ctrl-Alt-Down or Ctrl-Alt-Up on Windows.
Toggle line comment
You can toggle comments on a line of code or for multiple lines of code at once. To do so, select the desired lines of code and hit the shortcut for your operating system.
Mac: Cmd-/
Windows: Ctrl-/
Additionally, you can use block comments if your language supports it.
Mac: Option-Shift-A
Windows: Option-Shift-A
Column (box) selection
Column Selection is very handy when you need to edit a whole column of text. To do so, place the cursor in one corner and then hold Option-Shift (Mac) / Alt-Shift (Windows) while dragging to the opposite corner to create a selection.
Bracket matching
When you click near a parenthesis, square bracket, or curly brace, the editor highlights that character and its matching bracket so you can make sure you have complete and matching sets.
Side-by-side diff in version history
When displaying a previous version of your notebook, the new notebook editor will display side-by-side diffs to easily see what changed.
Python code formatting
Databricks now supports Black, a PEP 8 compatible code formatter. Black formats all code the same so you spend less time formatting and more time creating what matters. All Black-formatted code is styled the same, regardless of what project you are reviewing, so code reviews go faster too.
To use Black, connect to a cluster on DBR 11.2 or later. You can format a single Python cell by clicking on the cell Edit menu, indicated by the down chevron, and clicking "Format Python". You can also format multiple selected cells or the entire notebook by clicking on the global Edit menu in the header and selecting "Format cell(s)" or "Format notebook" respectively.
Run selected text
While troubleshooting a long block of code, it can be helpful to only execute a few lines. Databricks now supports "Run selected text" in Notebooks. You can highlight one or more lines within a cell, open the Run menu, and select "Run selected text" to execute only those lines. This ensures that you can test the smallest portion of code to identify and fix any errors there, to reduce the time you spend debugging.
Enabling the new notebook editor
Our new editor is now in preview and available to the public but is not enabled by default. To enable the new editor in the Notebook:
- Click your username at the top right of the workspace and select User Settings from the drop down.
- Click the Notebook Settings tab.
- Check the box next to Turn on the new notebook editor.
To try it out yourself, import the example notebook in this repo into your Databricks workspace.
In summary
At Databricks, we continually work to improve the development experience for all our users. The Notebook is the front door of the Databricks Lakehouse, and we want it to be the best data-native development tool in the market. Earlier this year, we simplified the UI, improved Jupyter compatibility, and added Bamboolib for analysis and visualizations.
This is just the start. Our new editor for Notebooks also opens the door to future potential improvements for language services that will allow us to improve our Notebooks developer experience even more throughout 2023.