Skip to content

Commit

Permalink
[NumPy] Remove references to deprecated NumPy type aliases.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hawkinsp authored and fedjax authors committed Dec 15, 2022
1 parent b47ce2c commit f57e045
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion fedjax/core/client_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions fedjax/core/serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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):
Expand All @@ -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]), []
]
]
]
Expand All @@ -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, [])

Expand Down
14 changes: 7 additions & 7 deletions fedjax/datasets/scripts/sent140/data_to_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fedjax/datasets/shakespeare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
6 changes: 3 additions & 3 deletions fedjax/datasets/stackoverflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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':
np.array([b'answer', b'question'])
}), {
'tokens':
np.array([b'this is a test', b'may it not fail'],
dtype=np.object),
dtype=object),
'domain_id': [1, 0]
})

Expand All @@ -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'):
Expand Down

0 comments on commit f57e045

Please sign in to comment.