question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with isort --float-to-top when the first cell is markdown

See original GitHub issue

Hello, 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)

image

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tqa236commented, Oct 20, 2022

@MarcoGorelli It works perfectly. Thanks a lot!

1reaction
mdeboccommented, Oct 20, 2022

@MarcoGorelli you’re fast!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found