Skip to content

Commit

Permalink
Remove references to deprecated NumPy type aliases.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 496324612
  • Loading branch information
hawkinsp authored and tfx-copybara committed Dec 19, 2022
1 parent d4758dd commit a092f1d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ def testPredictList(self):

# Check that SparseFeatures were correctly populated.
self.assertAllEqual(
np.array([b'cat'], dtype=np.object),
np.array([b'cat'], dtype=object),
features_predictions_labels_list[0].features['animals'][
encoding.NODE_SUFFIX].values)
self.assertAllEqual(
np.array([b'dog'], dtype=np.object),
np.array([b'dog'], dtype=object),
features_predictions_labels_list[1].features['animals'][
encoding.NODE_SUFFIX].values)
self.assertAllEqual(
np.array([b'cat', b'dog'], dtype=np.object),
np.array([b'cat', b'dog'], dtype=object),
features_predictions_labels_list[2].features['animals'][
encoding.NODE_SUFFIX].values)
self.assertAllEqual(
np.array([], dtype=np.object),
np.array([], dtype=object),
features_predictions_labels_list[3].features['animals'][
encoding.NODE_SUFFIX].values)

Expand Down
2 changes: 1 addition & 1 deletion tensorflow_model_analysis/eval_saved_model/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _dense_concat_rows(arrays: List[np.ndarray]) -> np.ndarray:
raise ValueError('arrays must be a non-empty list.')

shape_max = np.amax(np.array([a.shape for a in arrays]), axis=0)
if arrays[0].dtype == np.object:
if arrays[0].dtype == object:
# Assume if the dtype is object then the array contains strings.
padding_value = ''
else:
Expand Down
11 changes: 5 additions & 6 deletions tensorflow_model_analysis/eval_saved_model/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,24 @@ def testSplitTensorValueSparseTypesPreserved(self):
split_tensor_values = util.split_tensor_value(
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 0], [0, 1], [2, 0], [3, 1]]),
values=np.array(['zero0', 'zero1', 'two0', 'three1'],
dtype=np.object),
values=np.array(['zero0', 'zero1', 'two0', 'three1'], dtype=object),
dense_shape=np.array([4, 3])))
expected_sparse_tensor_values = [
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 0], [0, 1]]),
values=np.array(['zero0', 'zero1'], dtype=np.object),
values=np.array(['zero0', 'zero1'], dtype=object),
dense_shape=np.array([1, 2])),
tf.compat.v1.SparseTensorValue(
indices=np.zeros([0, 2], dtype=np.int64),
values=np.zeros([0], dtype=np.object),
values=np.zeros([0], dtype=object),
dense_shape=np.array([1, 0])),
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 0]]),
values=np.array(['two0'], dtype=np.object),
values=np.array(['two0'], dtype=object),
dense_shape=np.array([1, 1])),
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 1]]),
values=np.array(['three1'], dtype=np.object),
values=np.array(['three1'], dtype=object),
dense_shape=np.array([1, 2])),
]
for expected_sparse_tensor_value, got_sparse_tensor_value in zip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2740,8 +2740,7 @@ def check_result(got_sliced_metrics):
tn=[0.0, 2.0, 2.0],
fn=[0.0, 1.0, 2.0]), False),
('BytesNotDiffable', b'some bytes', False),
('NumpyObjectDtypeNotDiffable', np.array(['obj'],
dtype=np.object), False),
('NumpyObjectDtypeNotDiffable', np.array(['obj'], dtype=object), False),
)
def testIsMetricDiffable(self, metric_value, expected_is_diffable):
self.assertEqual(
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_model_analysis/metrics/metric_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def testPrepareLabelsAndPredictionsWithVocab(self):
self.assertAllClose(got_preds, np.array([0.2, 0.8]))

def testPrepareLabelsAndPredictionsWithVocabUsingObjectType(self):
labels = np.array(['e', 'f'], dtype=np.object)
labels = np.array(['e', 'f'], dtype=object)
preds = {'probabilities': [0.2, 0.8], 'all_classes': ['a', 'b', 'c']}
got_labels, got_preds = metric_util.prepare_labels_and_predictions(
labels, preds, label_vocabulary=['e', 'f'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ def testExtractFplExampleGraph(self):
expected_language = [
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 0]]),
values=np.array([b'english'], dtype=np.object),
values=np.array([b'english'], dtype=object),
dense_shape=np.array([1, 1])),
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 0]]),
values=np.array([b'chinese'], dtype=np.object),
values=np.array([b'chinese'], dtype=object),
dense_shape=np.array([1, 1])),
tf.compat.v1.SparseTensorValue(
indices=np.array([], dtype=np.int64).reshape([0, 2]),
values=np.array([], dtype=np.object),
values=np.array([], dtype=object),
dense_shape=np.array([1, 0])),
tf.compat.v1.SparseTensorValue(
indices=np.array([[0, 0]]),
values=np.array([b'chinese'], dtype=np.object),
values=np.array([b'chinese'], dtype=object),
dense_shape=np.array([1, 1]))
]
expected_probabilities = [
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_model_analysis/utils/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ def testSplitThenMergeAllowingScalarNumpyArray(self):
self.assertEqual(remerged_got['predictions'].dtype, np.float64)
self.assertEqual(remerged_got['labels'].dtype, np.float64)
self.assertEqual(remerged_got['array_scalar'].dtype, np.float64)
self.assertEqual(remerged_got['objects'].dtype, np.object)
self.assertEqual(remerged_got['objects'].dtype, object)

def testSplitThenMergeDisallowingScalars(self):
extract = {
Expand Down

0 comments on commit a092f1d

Please sign in to comment.