Repository: googleapis/python-bigquery

Issue:
%%bigquery ipython / jupyter notebook magics prerelease tests failing
Currently getting failing prerelease tests on `main` branch: https://github.com/googleapis/python-bigquery/commit/a2520cabf7ec6bcb923c21e338188f1c10dc4d5d, https://source.cloud.google.com/results/invocations/c18d2f75-e792-4c1e-b0fb-fd4ea7632970/targets, https://source.cloud.google.com/results/invocations/a6ab5f6d-4c9a-401b-9a07-ab55e301e84f/targets

Potential incompatibility between tqdm, ipython, and jupyter widgets packages?

```
tests/unit/test_magics.py .F.Exception ignored in: <function tqdm.__del__ at 0x7eff697bd3a0>
Traceback (most recent call last):
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/std.py", line 1145, in __del__
    self.close()
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/notebook.py", line 283, in close
    self.disp(bar_style='danger', check_delay=False)
AttributeError: 'tqdm_notebook' object has no attribute 'disp'
F...............................FException ignored in: <function tqdm.__del__ at 0x7eff697bd3a0>
Traceback (most recent call last):
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/std.py", line 1145, in __del__
    self.close()
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/notebook.py", line 283, in close
    self.disp(bar_style='danger', check_delay=False)
AttributeError: 'tqdm_notebook' object has no attribute 'disp'
FException ignored in: <function tqdm.__del__ at 0x7eff697bd3a0>
Traceback (most recent call last):
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/std.py", line 1145, in __del__
    self.close()
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/notebook.py", line 283, in close
    self.disp(bar_style='danger', check_delay=False)
AttributeError: 'tqdm_notebook' object has no attribute 'disp'
FException ignored in: <function tqdm.__del__ at 0x7eff697bd3a0>
Traceback (most recent call last):
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/std.py", line 1145, in __del__
    self.close()
  File "/tmpfs/src/github/python-bigquery/.nox/prerelease_deps-3-8/lib/python3.8/site-packages/tqdm/notebook.py", line 283, in close
    self.disp(bar_style='danger', check_delay=False)
AttributeError: 'tqdm_notebook' object has no attribute 'disp'
F....... [ 48%]
```

```
self = <ipywidgets.widgets.trait_types.InstanceDict object at 0x7eff68b55c10>
obj = <[ModuleNotFoundError("No module named 'ipykernel'") raised in repr()] FloatProgress object at 0x7eff66707af0>
cls = <class 'ipywidgets.widgets.widget_float.FloatProgress'>

    def get(self, obj, cls=None):
        try:
>           value = obj._trait_values[self.name]
E           KeyError: 'layout'

.nox/prerelease_deps-3-8/lib/python3.8/site-packages/traitlets/traitlets.py:656: KeyError
```


Discussion:

Resolving patch:
diff --git a/noxfile.py b/noxfile.py
--- a/noxfile.py
+++ b/noxfile.py
@@ -303,6 +303,10 @@ def prerelease_deps(session):
     session.install(
         "--pre",
         "--upgrade",
+        "IPython",
+        "ipykernel",
+        "ipywidgets",
+        "tqdm",
         "git+https://github.com/pypa/packaging.git",
     )
 
@@ -321,7 +325,6 @@ def prerelease_deps(session):
         "google-cloud-datacatalog",
         "google-cloud-storage",
         "google-cloud-testutils",
-        "IPython",
         "mock",
         "psutil",
         "pytest",
@@ -356,6 +359,7 @@ def prerelease_deps(session):
     session.run("python", "-c", "import grpc; print(grpc.__version__)")
     session.run("python", "-c", "import pandas; print(pandas.__version__)")
     session.run("python", "-c", "import pyarrow; print(pyarrow.__version__)")
+    session.run("python", "-m", "pip", "freeze")
 
     # Run all tests, except a few samples tests which require extra dependencies.
     session.run("py.test", "tests/unit")
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -67,9 +67,15 @@
         pyarrow_dependency,
         "db-dtypes>=0.3.0,<2.0.0dev",
     ],
-    "ipywidgets": ["ipywidgets>=7.7.0,<8.0.1"],
+    "ipywidgets": [
+        "ipywidgets>=7.7.0",
+        "ipykernel>=6.0.0",
+    ],
     "geopandas": ["geopandas>=0.9.0, <1.0dev", "Shapely>=1.8.4, <2.0dev"],
-    "ipython": ["ipython>=7.0.1,!=8.1.0"],
+    "ipython": [
+        "ipython>=7.23.1,!=8.1.0",
+        "ipykernel>=6.0.0",
+    ],
     "tqdm": ["tqdm >= 4.7.4, <5.0.0dev"],
     "opentelemetry": [
         "opentelemetry-api >= 1.1.0",


Test patch:
diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt
--- a/testing/constraints-3.7.txt
+++ b/testing/constraints-3.7.txt
@@ -13,7 +13,8 @@ google-cloud-core==1.6.0
 google-resumable-media==0.6.0
 grpcio==1.47.0
 ipywidgets==7.7.1
-ipython==7.0.1
+ipython==7.23.1
+ipykernel==6.0.0
 opentelemetry-api==1.1.0
 opentelemetry-instrumentation==0.20b0
 opentelemetry-sdk==1.1.0