Bug with isort --float-to-top when the first cell is markdown
See original GitHub issueHello, thanks a lot for this awesome tool. I’m able to use it with a lot of libraries, but I run into a small problem with isort
Problem
I have a simple Jupyter notebook as below (first cell is a markdown)
When using nbqa-diff
, the diff looks correct
❯ python -m nbqa isort --float-to-top "notebook/Test.ipynb" --nbqa-diff
Cell 1
------
--- notebook/Test.ipynb
+++ notebook/Test.ipynb
@@ -1 +1,2 @@
+import time
Cell 2
------
--- notebook/Test.ipynb
+++ notebook/Test.ipynb
@@ -1 +1 @@
-import time
+
When applying the change, it’s no longer correct (all imports are removed)
> python -m nbqa isort --float-to-top "notebook/Test.ipynb"
> git diff
diff --git a/notebook/Test.ipynb b/notebook/Test.ipynb
index fd0d300..feb9898 100644
--- a/notebook/Test.ipynb
+++ b/notebook/Test.ipynb
@@ -8,25 +8,13 @@
"Markdown"
]
},
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "8b3f984a-826b-443e-bacf-bbed12c07bd2",
- "metadata": {},
- "outputs": [],
- "source": [
- "import os"
- ]
- },
{
"cell_type": "code",
"execution_count": null,
"id": "50731a1b-213b-4485-91bf-2d80fb522371",
"metadata": {},
"outputs": [],
- "source": [
- "import time"
- ]
+ "source": []
}
],
"metadata": {
Version
OS: Ubuntu 22.04 on WSL (Windows 11)
Python 3.10.6
nbqa==1.5.2
isort==5.10.1
Is this a bug or do I use nbqa
incorrectly? If it is a bug, can you fix it, please? Thank you very much.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Actions · nbQA-dev/nbQA - GitHub
Run isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks ... Bug with isort --float-to-top when the first cell is markdown tox...
Read more >nbQA Documentation
Fixed bug when running isort --float-to-top and it was removing the wrong cell (thanks @tqa236 for the report!) 6.2 1.5.2 (2022-09-28).
Read more >nbqa - PyPI
nbqa isort my_notebook.ipynb --float-to-top Fixing my_notebook.ipynb. Upgrade your syntax with pyupgrade: ... Format your markdown cells with blacken-docs:
Read more >8 Great Cheatsheets for Web Devs - Morioh
this article covers the most awesome cheat sheet resources that will make you code faster and easier.
Read more >isort is a Python utility / library to sort imports alphabetically ...
Fixed #1612: In rare circumstances an extra comma is added after import and before comment. · Fixed #1593: isort encounters bug in Python...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MarcoGorelli It works perfectly. Thanks a lot!
@MarcoGorelli you’re fast!