From f57e0451b7a381f456266def47a24d69499fdb1b Mon Sep 17 00:00:00 2001 From: Peter Hawkins Date: Wed, 14 Dec 2022 17:01:44 -0800 Subject: [PATCH] [NumPy] Remove references to deprecated NumPy type aliases. This change replaces references to a number of deprecated NumPy type aliases (np.bool, np.int, np.float, np.complex, np.object, np.str) with their recommended replacement (bool, int, float, complex, object, str). NumPy 1.24 drops the deprecated aliases, so we must remove uses before updating NumPy. PiperOrigin-RevId: 495456585 --- fedjax/core/client_samplers.py | 2 +- fedjax/core/serialization_test.py | 8 ++++---- fedjax/datasets/scripts/sent140/data_to_sqlite.py | 14 +++++++------- fedjax/datasets/shakespeare_test.py | 2 +- fedjax/datasets/stackoverflow_test.py | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/fedjax/core/client_samplers.py b/fedjax/core/client_samplers.py index 2515367..8b61ad7 100644 --- a/fedjax/core/client_samplers.py +++ b/fedjax/core/client_samplers.py @@ -104,7 +104,7 @@ def sample( # Explicitly specify dtype as np.object to prevent numpy from stripping # trailing zero bytes from client ids that resulted in lookup KeyErrors. client_ids = random_state.choice( - np.array(self._client_ids, dtype=np.object), + np.array(self._client_ids, dtype=object), size=self._num_clients, replace=False) client_rngs = jax.random.split( diff --git a/fedjax/core/serialization_test.py b/fedjax/core/serialization_test.py index 4d93bfe..34c4b39 100644 --- a/fedjax/core/serialization_test.py +++ b/fedjax/core/serialization_test.py @@ -28,7 +28,7 @@ def test_dict(self): 'float64': -np.arange(4, dtype=np.float64).reshape([1, 4]), 'bytes': - np.array([b'a', b'bc', b'def'], dtype=np.object).reshape([3, 1]), + np.array([b'a', b'bc', b'def'], dtype=object).reshape([3, 1]), } output = serialization.msgpack_deserialize( serialization.msgpack_serialize(original)) @@ -37,7 +37,7 @@ def test_dict(self): npt.assert_array_equal(output['int32'], original['int32']) self.assertEqual(output['float64'].dtype, np.float64) npt.assert_array_equal(output['float64'], original['float64']) - self.assertEqual(output['bytes'].dtype, np.object) + self.assertEqual(output['bytes'].dtype, object) npt.assert_array_equal(output['bytes'], original['bytes']) def test_nested_list(self): @@ -47,7 +47,7 @@ def test_nested_list(self): -np.arange(4, dtype=np.float64).reshape([1, 4]), [ np.array([b'a', b'bc', b'def'], - dtype=np.object).reshape([3, 1]), [] + dtype=object).reshape([3, 1]), [] ] ] ] @@ -60,7 +60,7 @@ def test_nested_list(self): self.assertEqual(float64_array.dtype, np.float64) npt.assert_array_equal(float64_array, original[1][0]) bytes_array, rest = rest - self.assertEqual(bytes_array.dtype, np.object) + self.assertEqual(bytes_array.dtype, object) npt.assert_array_equal(bytes_array, original[1][1][0]) self.assertEqual(rest, []) diff --git a/fedjax/datasets/scripts/sent140/data_to_sqlite.py b/fedjax/datasets/scripts/sent140/data_to_sqlite.py index b28ac25..8285aac 100644 --- a/fedjax/datasets/scripts/sent140/data_to_sqlite.py +++ b/fedjax/datasets/scripts/sent140/data_to_sqlite.py @@ -113,13 +113,13 @@ def user_data_to_numpy(user_data: List[List[str]]) -> Dict[str, np.ndarray]: tweet_sentiment.append(bytes(y, 'utf-8')) np_data = { - 'tweet_id': np.array(tweet_id, dtype=np.object), - 'tweet_date': np.array(tweet_date, dtype=np.object), - 'tweet_query': np.array(tweet_query, dtype=np.object), - 'tweet_client': np.array(tweet_client, dtype=np.object), - 'tweet_text': np.array(tweet_text, dtype=np.object), - 'tweet_dataset': np.array(tweet_dataset, dtype=np.object), - 'tweet_sentiment': np.array(tweet_sentiment, dtype=np.object) + 'tweet_id': np.array(tweet_id, dtype=object), + 'tweet_date': np.array(tweet_date, dtype=object), + 'tweet_query': np.array(tweet_query, dtype=object), + 'tweet_client': np.array(tweet_client, dtype=object), + 'tweet_text': np.array(tweet_text, dtype=object), + 'tweet_dataset': np.array(tweet_dataset, dtype=object), + 'tweet_sentiment': np.array(tweet_sentiment, dtype=object) } return np_data diff --git a/fedjax/datasets/shakespeare_test.py b/fedjax/datasets/shakespeare_test.py index 9386f6c..e9069a6 100644 --- a/fedjax/datasets/shakespeare_test.py +++ b/fedjax/datasets/shakespeare_test.py @@ -26,7 +26,7 @@ class ShakespeareTest(absltest.TestCase): def test_preprocess_client(self): examples = shakespeare.preprocess_client( - None, {'snippets': np.array([b'hello', b'hi there'], dtype=np.object)}, + None, {'snippets': np.array([b'hello', b'hi there'], dtype=object)}, sequence_length=10) npt.assert_equal( examples, { diff --git a/fedjax/datasets/stackoverflow_test.py b/fedjax/datasets/stackoverflow_test.py index 4cf2625..8eef941 100644 --- a/fedjax/datasets/stackoverflow_test.py +++ b/fedjax/datasets/stackoverflow_test.py @@ -30,7 +30,7 @@ def test_preprocess_client(self): None, { 'tokens': np.array([b'this is a test', b'may it not fail'], - dtype=np.object), + dtype=object), 'creation_date': np.array([b'1970-01-01', b'2021-04-20']), 'type': @@ -38,7 +38,7 @@ def test_preprocess_client(self): }), { 'tokens': np.array([b'this is a test', b'may it not fail'], - dtype=np.object), + dtype=object), 'domain_id': [1, 0] }) @@ -49,7 +49,7 @@ def test_tokenizer(self): examples = { 'tokens': np.array([b'three four five', b'five three four five six'], - dtype=np.object) + dtype=object) } with self.subTest('padding and truncation'):