Skip to content

Commit 1c4cfff

Browse files
committed
Fix users of NumPy APIs that are removed in NumPy 2.0.
This change migrates users of APIs removed in NumPy 2.0 to their recommended replacements (https://numpy.org/devdocs/numpy_2_0_migration_guide.html). PiperOrigin-RevId: 655943417
1 parent 03987b2 commit 1c4cfff

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

tensorflow_data_validation/api/stats_api_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_stats_pipeline(self):
5151
pa.array([np.linspace(1, 500, 500, dtype=np.int32)]),
5252
], ['a', 'b', 'c']),
5353
pa.RecordBatch.from_arrays([
54-
pa.array([[3.0, 4.0, np.NaN, 5.0]]),
54+
pa.array([[3.0, 4.0, np.nan, 5.0]]),
5555
pa.array([['a', 'c', '∞', 'a']]),
5656
pa.array([np.linspace(501, 1250, 750, dtype=np.int32)]),
5757
], ['a', 'b', 'c']),

tensorflow_data_validation/statistics/generators/basic_stats_generator_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def test_with_weight_feature(self):
826826
pa.array([[1.0], [2.0]])
827827
], ['a', 'b', 'w'])
828828
b2 = pa.RecordBatch.from_arrays([
829-
pa.array([[1.0, np.NaN, np.NaN, np.NaN], None]),
829+
pa.array([[1.0, np.nan, np.nan, np.nan], None]),
830830
pa.array([[1], None]),
831831
pa.array([[3.0], [2.0]])
832832
], ['a', 'b', 'w'])
@@ -1269,7 +1269,7 @@ def test_with_per_feature_weight(self):
12691269
pa.array([[2.0], [1.0]]),
12701270
], ['a', 'b', 'w_a', 'w_b'])
12711271
b2 = pa.RecordBatch.from_arrays([
1272-
pa.array([[1.0, np.NaN, np.NaN, np.NaN], None]),
1272+
pa.array([[1.0, np.nan, np.nan, np.nan], None]),
12731273
pa.array([[1], None]),
12741274
pa.array([[3.0], [2.0]]),
12751275
pa.array([[2.0], [3.0]]),
@@ -1706,8 +1706,8 @@ def test_with_individual_feature_value_missing(self):
17061706
# input with two batches: first batch has two examples and second batch
17071707
# has a single example.
17081708
b1 = pa.RecordBatch.from_arrays(
1709-
[pa.array([[1.0, 2.0], [3.0, 4.0, np.NaN, 5.0]])], ['a'])
1710-
b2 = pa.RecordBatch.from_arrays([pa.array([[np.NaN, 1.0]])], ['a'])
1709+
[pa.array([[1.0, 2.0], [3.0, 4.0, np.nan, 5.0]])], ['a'])
1710+
b2 = pa.RecordBatch.from_arrays([pa.array([[np.nan, 1.0]])], ['a'])
17111711
batches = [b1, b2]
17121712

17131713
expected_result = {
@@ -2286,7 +2286,7 @@ def test_no_value_in_batch(self):
22862286

22872287
def test_only_nan(self):
22882288
b1 = pa.RecordBatch.from_arrays(
2289-
[pa.array([[np.NaN]], type=pa.list_(pa.float32()))], ['a'])
2289+
[pa.array([[np.nan]], type=pa.list_(pa.float32()))], ['a'])
22902290
batches = [b1]
22912291
expected_result = {
22922292
types.FeaturePath(['a']): text_format.Parse(

tensorflow_data_validation/statistics/generators/mutual_information_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_encoder_feature_excluded(self):
8181

8282
def test_encoder_multivalent_numerical_with_nulls(self):
8383
batch = pa.RecordBatch.from_arrays(
84-
[pa.array([[1.0, 1.0, np.NaN], None, [2.0, 2.0, 1.0], []])], ["fa"])
84+
[pa.array([[1.0, 1.0, np.nan], None, [2.0, 2.0, 1.0], []])], ["fa"])
8585
expected = {
8686
types.FeaturePath(["fa"]): [[2, 0, 0], [None, None, None], [1, 0, 2],
8787
[None, None, None]]
@@ -92,7 +92,7 @@ def test_encoder_multivalent_numerical_with_nulls(self):
9292

9393
def test_encoder_univalent_with_nulls(self):
9494
batch = pa.RecordBatch.from_arrays(
95-
[pa.array([None, [2.0], [], [None], [np.NaN]])], ["fa"])
95+
[pa.array([None, [2.0], [], [None], [np.nan]])], ["fa"])
9696
expected = {
9797
types.FeaturePath(["fa"]): [[None], [2], [None], [None], [None]]
9898
}
@@ -205,7 +205,7 @@ def test_mi_with_univalent_features(self):
205205
label_array = pa.array([[0.1], [0.2], [0.7], [0.2], None, [0.9], [0.4],
206206
[0.8]])
207207
# Random floats that do not map onto the label
208-
terrible_feat_array = pa.array([[0.4], [0.1], [0.4], [np.NaN], [0.8], [0.2],
208+
terrible_feat_array = pa.array([[0.4], [0.1], [0.4], [np.nan], [0.8], [0.2],
209209
[0.5], [0.1]])
210210
batch = pa.RecordBatch.from_arrays(
211211
[label_array, label_array, terrible_feat_array],
@@ -318,7 +318,7 @@ def test_mi_batch_smaller_than_k(self):
318318
def test_mi_normalized(self):
319319
label_array = pa.array([[0.1], [0.2], [0.7], [0.2], None, [0.9], [0.4],
320320
[0.8]])
321-
terrible_feat_array = pa.array([[0.4], [0.1], [0.4], [np.NaN], [0.8], [0.2],
321+
terrible_feat_array = pa.array([[0.4], [0.1], [0.4], [np.nan], [0.8], [0.2],
322322
[0.5], [0.1]])
323323
batch = pa.RecordBatch.from_arrays(
324324
[label_array, label_array, terrible_feat_array],
@@ -468,7 +468,7 @@ def test_mi_with_unicode_labels(self):
468468

469469
def test_mi_with_univalent_feature_all_null(self):
470470
label_array = pa.array([[0.1], [0.2], [0.7], [0.7]])
471-
null_feat_array = pa.array([[np.NaN], [np.NaN], [np.NaN], [np.NaN]])
471+
null_feat_array = pa.array([[np.nan], [np.nan], [np.nan], [np.nan]])
472472
batch = pa.RecordBatch.from_arrays([label_array, null_feat_array],
473473
["label_key", "null_feature"])
474474

@@ -510,7 +510,7 @@ def test_mi_with_univalent_feature_all_null(self):
510510

511511
def test_mi_with_multivalent_feature_all_null(self):
512512
label_array = pa.array([[0.1], [0.2], [0.7], [0.7]])
513-
null_feat_array = pa.array([[np.NaN], [np.NaN], [np.NaN], [np.NaN]])
513+
null_feat_array = pa.array([[np.nan], [np.nan], [np.nan], [np.nan]])
514514
batch = pa.RecordBatch.from_arrays([label_array, null_feat_array],
515515
["label_key", "null_feature"])
516516

@@ -551,7 +551,7 @@ def test_mi_with_multivalent_feature_all_null(self):
551551

552552
def test_mi_with_multivalent_feature_all_empty(self):
553553
label_array = pa.array([[0.1], [0.2], [0.7], [0.7]])
554-
empty_feat_array = pa.array([[np.NaN], [], [], []])
554+
empty_feat_array = pa.array([[np.nan], [], [], []])
555555
batch = pa.RecordBatch.from_arrays([label_array, empty_feat_array],
556556
["label_key", "empty_feature"])
557557

@@ -633,7 +633,7 @@ def test_mi_with_multivalent_feature_univalent_label(self):
633633
types.FeaturePath(["label_key"]))
634634

635635
def test_mi_with_multivalent_numeric_feature(self):
636-
feat_array = pa.array([[3.1], None, [4.0], [np.NaN], [1.2, 8.5], [2.3],
636+
feat_array = pa.array([[3.1], None, [4.0], [np.nan], [1.2, 8.5], [2.3],
637637
[1.2, 3.2, 3.9]])
638638
label_array = pa.array([[3.3], None, [4.0], [2.0, 8.0], [1.3, 8.5], [2.3],
639639
[1.0, 3.1, 4]])
@@ -1395,7 +1395,7 @@ def setUp(self):
13951395
], ["fa", "fb", "fc", "fd", "label_key"]),
13961396
pa.RecordBatch.from_arrays([
13971397
pa.array([["1"]]),
1398-
pa.array([[np.NaN]], type=pa.list_(pa.float64())),
1398+
pa.array([[np.nan]], type=pa.list_(pa.float64())),
13991399
pa.array([["0", "0"]]),
14001400
pa.array([[0.0, 0.2]]),
14011401
pa.array([["label"]]),

tensorflow_data_validation/statistics/generators/partitioned_stats_generator_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def setUp(self):
567567
pa.array([['Green']]),
568568
pa.array([[2.3]]),
569569
pa.array([[0]]),
570-
pa.array([[np.NaN]], type=pa.list_(pa.float64())),
570+
pa.array([[np.nan]], type=pa.list_(pa.float64())),
571571
pa.array([['Label']]),
572572
], ['fa', 'fb', 'fc', 'fd', 'label_key']),
573573
pa.RecordBatch.from_arrays([

tensorflow_data_validation/statistics/generators/sklearn_mutual_information_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def test_mi_with_imputed_numerical_feature(self):
612612
[0.1], [0.2], [0.8], [0.7], [0.2], [0.2], [0.3],
613613
[0.1], [0.2], [0.8], [0.7], [0.2], [0.2], [0.3]])
614614
feat_array = pa.array([
615-
[0.1], [0.2], [0.8], [0.7], [0.2], [np.NaN], None,
615+
[0.1], [0.2], [0.8], [0.7], [0.2], [np.nan], None,
616616
[0.1], [0.2], [0.8], [0.7], [0.2], [0.2], [0.3]])
617617
batch = pa.RecordBatch.from_arrays([label_array, feat_array],
618618
["label_key", "fa"])
@@ -716,7 +716,7 @@ def test_mi_with_imputed_categorical_label(self):
716716

717717
def test_mi_with_imputed_numerical_label(self):
718718
label_array = pa.array([
719-
[0.1], [0.2], [0.8], [0.7], [0.2], [np.NaN], None,
719+
[0.1], [0.2], [0.8], [0.7], [0.2], [np.nan], None,
720720
[0.1], [0.2], [0.8], [0.7], [0.2], [0.2], [0.3]])
721721
feat_array = pa.array([
722722
[0.1], [0.2], [0.8], [0.7], [0.2], [0.2], [0.3],

tensorflow_data_validation/statistics/stats_impl_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def extract_output(self, accumulator):
117117
pa.array([np.linspace(1, 500, 500, dtype=np.int64)]),
118118
], ['a', 'b', 'c']),
119119
pa.RecordBatch.from_arrays([
120-
pa.array([[3.0, 4.0, np.NaN, 5.0]], type=pa.list_(
120+
pa.array([[3.0, 4.0, np.nan, 5.0]], type=pa.list_(
121121
pa.float32())),
122122
pa.array([[b'a', b'c', b'd', b'a']], type=pa.list_(
123123
pa.binary())),
@@ -1891,7 +1891,7 @@ def extract_output(self, accumulator):
18911891
pa.array([np.linspace(1, 500, 500, dtype=np.int64)]),
18921892
], ['a', 'b', 'c']),
18931893
pa.RecordBatch.from_arrays([
1894-
pa.array([[3.0, 4.0, np.NaN, 5.0]], type=pa.list_(pa.float32())),
1894+
pa.array([[3.0, 4.0, np.nan, 5.0]], type=pa.list_(pa.float32())),
18951895
pa.array([[b'a', b'b']], type=pa.list_(pa.binary())),
18961896
pa.array([np.linspace(501, 1250, 750, dtype=np.int64)]),
18971897
], ['a', 'b', 'c']),
@@ -2015,7 +2015,7 @@ def extract_output(self, accumulator):
20152015
pa.array([np.linspace(1, 500, 500, dtype=np.int64)]),
20162016
], ['a', 'b', 'c']),
20172017
pa.RecordBatch.from_arrays([
2018-
pa.array([[3.0, 4.0, np.NaN, 5.0]], type=pa.list_(
2018+
pa.array([[3.0, 4.0, np.nan, 5.0]], type=pa.list_(
20192019
pa.float32())),
20202020
pa.array([[b'a', b'b']], type=pa.list_(pa.binary())),
20212021
pa.array([np.linspace(501, 1250, 750, dtype=np.int64)]),
@@ -2114,7 +2114,7 @@ def test_stats_impl_slicing_sql(self):
21142114
pa.array([np.linspace(1, 500, 500, dtype=np.int64)]),
21152115
], ['a', 'b', 'c']),
21162116
pa.RecordBatch.from_arrays([
2117-
pa.array([[3.0, 4.0, np.NaN, 5.0]], type=pa.list_(
2117+
pa.array([[3.0, 4.0, np.nan, 5.0]], type=pa.list_(
21182118
pa.float32())),
21192119
pa.array([[b'a', b'b']], type=pa.list_(pa.binary())),
21202120
pa.array([np.linspace(501, 1250, 750, dtype=np.int64)]),
@@ -2160,7 +2160,7 @@ def test_stats_impl_slicing_sql_in_config(self):
21602160
pa.array([np.linspace(1, 500, 500, dtype=np.int64)]),
21612161
], ['a', 'b', 'c']),
21622162
pa.RecordBatch.from_arrays([
2163-
pa.array([[3.0, 4.0, np.NaN, 5.0]], type=pa.list_(
2163+
pa.array([[3.0, 4.0, np.nan, 5.0]], type=pa.list_(
21642164
pa.float32())),
21652165
pa.array([[b'a', b'b']], type=pa.list_(pa.binary())),
21662166
pa.array([np.linspace(501, 1250, 750, dtype=np.int64)]),
@@ -2677,7 +2677,7 @@ def test_tfdv_telemetry(self):
26772677
pa.array([None]),
26782678
], ['a', 'b', 'c']),
26792679
pa.RecordBatch.from_arrays([
2680-
pa.array([[3.0, 4.0, np.NaN, 5.0]]),
2680+
pa.array([[3.0, 4.0, np.nan, 5.0]]),
26812681
pa.array([['d', 'e', 'f']]),
26822682
pa.array([None]),
26832683
], ['a', 'b', 'c']),

0 commit comments

Comments
 (0)