Skip to content

Commit 682c93f

Browse files
bmd3kyatbear
authored andcommitted
Fix tests to be compatible with numpy>=1.23.0 and python>=3.9.0. (#5843)
Fix tests to be compatible with numpy>=1.23.0 and python>=3.9.0. It's possible nobody has run these tests locally in a while because I have numpy 1.23.1 and python 3.10.5 installed on my machine and these tests failed for me. Note that the numpy changes, specifically, were originally proposed internall in cl/465149745, which states: > NumPy 1.23 removes support for non-tuple indexing of NumPy arrays ([https://numpy.org/devdocs/release/1.23.0-notes.html#expired-deprecations](https://www.google.com/url?sa=D&q=https%3A%2F%2Fnumpy.org%2Fdevdocs%2Frelease%2F1.23.0-notes.html%23expired-deprecations)). The workaround is to convert multidimensional indices to a tuple. Python 3.9.0 removes collections.Callable. We should now use collections.abc.Callable.
1 parent 16df64e commit 682c93f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

tensorboard/plugins/metrics/metrics_plugin_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
import argparse
19-
import collections
19+
import collections.abc
2020
import os.path
2121

2222
import tensorflow.compat.v1 as tf1
@@ -165,7 +165,7 @@ def _get_image_blob_key(self, run, tag, step=0, sample=0):
165165
def test_routes_provided(self):
166166
"""Tests that the plugin offers the correct routes."""
167167
routes = self._plugin.get_plugin_apps()
168-
self.assertIsInstance(routes["/tags"], collections.Callable)
168+
self.assertIsInstance(routes["/tags"], collections.abc.Callable)
169169

170170
def test_tags_empty(self):
171171
response = self._plugin._tags_impl(context.RequestContext(), "eid")

tensorboard/plugins/text/text_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def reduce_to_2d(arr):
149149
raise ValueError("reduce_to_2d requires an array of dimensionality >=2")
150150
# slice(None) is equivalent to `:`, so we take arr[0,0,...0,:,:]
151151
slices = ([0] * (ndims - 2)) + [slice(None), slice(None)]
152-
return arr[slices]
152+
return arr[tuple(slices)]
153153

154154

155155
def text_array_to_html(text_arr, enable_markdown):

tensorboard/plugins/text_v2/text_v2_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def reduce_to_2d(arr):
5757
raise ValueError("reduce_to_2d requires an array of dimensionality >=2")
5858
# slice(None) is equivalent to `:`, so we take arr[0,0,...0,:,:]
5959
slices = ([0] * (ndims - 2)) + [slice(None), slice(None)]
60-
return arr[slices]
60+
return arr[tuple(slices)]
6161

6262

6363
def reduce_and_jsonify(text_ndarr):

0 commit comments

Comments
 (0)