From 47b439e376029a6f4a3130a635d005c0f4b5b06a Mon Sep 17 00:00:00 2001 From: Michael Reneer Date: Wed, 26 Jan 2022 13:55:56 -0800 Subject: [PATCH] Remove TensorFlow Privacy dependency on `six`. Python 2 is not supported, please use Python 3. PiperOrigin-RevId: 424435761 --- tensorflow_privacy/privacy/analysis/rdp_accountant.py | 6 +++--- .../privacy/analysis/rdp_privacy_accountant.py | 6 +++--- tensorflow_privacy/privacy/dp_query/gaussian_query_test.py | 3 +-- .../privacy/optimizers/dp_optimizer_eager_test.py | 1 - tensorflow_privacy/privacy/optimizers/dp_optimizer_test.py | 2 +- .../privacy/optimizers/dp_optimizer_vectorized_test.py | 1 - 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tensorflow_privacy/privacy/analysis/rdp_accountant.py b/tensorflow_privacy/privacy/analysis/rdp_accountant.py index 380ff9c..342d2e5 100644 --- a/tensorflow_privacy/privacy/analysis/rdp_accountant.py +++ b/tensorflow_privacy/privacy/analysis/rdp_accountant.py @@ -42,9 +42,9 @@ from __future__ import print_function import math import sys + import numpy as np from scipy import special -import six ######################## # LOG-SPACE ARITHMETIC # @@ -106,7 +106,7 @@ def _log_comb(n, k): def _compute_log_a_int(q, sigma, alpha): """Compute log(A_alpha) for integer alpha. 0 < q < 1.""" - assert isinstance(alpha, six.integer_types) + assert isinstance(alpha, int) # Initialize with 0 in the log space. log_a = -np.inf @@ -486,7 +486,7 @@ def _compute_rdp_sample_without_replacement_int(q, sigma, alpha): """ max_alpha = 256 - assert isinstance(alpha, six.integer_types) + assert isinstance(alpha, int) if np.isinf(alpha): return np.inf diff --git a/tensorflow_privacy/privacy/analysis/rdp_privacy_accountant.py b/tensorflow_privacy/privacy/analysis/rdp_privacy_accountant.py index 5c012a3..d03d1fd 100644 --- a/tensorflow_privacy/privacy/analysis/rdp_privacy_accountant.py +++ b/tensorflow_privacy/privacy/analysis/rdp_privacy_accountant.py @@ -19,7 +19,7 @@ from typing import Collection, Optional import numpy as np from scipy import special -import six + from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.analysis import privacy_accountant @@ -74,7 +74,7 @@ def _log_comb(n, k): def _compute_log_a_int(q, sigma, alpha): """Computes log(A_alpha) for integer alpha, 0 < q < 1.""" - assert isinstance(alpha, six.integer_types) + assert isinstance(alpha, int) # Initialize with 0 in the log space. log_a = -np.inf @@ -430,7 +430,7 @@ def _compute_rdp_sample_wor_gaussian_int(q, sigma, alpha): """ max_alpha = 256 - assert isinstance(alpha, six.integer_types) + assert isinstance(alpha, int) if np.isinf(alpha): return np.inf diff --git a/tensorflow_privacy/privacy/dp_query/gaussian_query_test.py b/tensorflow_privacy/privacy/dp_query/gaussian_query_test.py index cd9fe61..ee76bf8 100644 --- a/tensorflow_privacy/privacy/dp_query/gaussian_query_test.py +++ b/tensorflow_privacy/privacy/dp_query/gaussian_query_test.py @@ -19,7 +19,6 @@ from __future__ import print_function from absl.testing import parameterized import numpy as np -from six.moves import xrange import tensorflow.compat.v1 as tf from tensorflow_privacy.privacy.dp_query import gaussian_query @@ -81,7 +80,7 @@ class GaussianQueryTest(tf.test.TestCase, parameterized.TestCase): query_result, _ = test_utils.run_query(query, [record1, record2]) noised_sums = [] - for _ in xrange(1000): + for _ in range(1000): noised_sums.append(sess.run(query_result)) result_stddev = np.std(noised_sums) diff --git a/tensorflow_privacy/privacy/optimizers/dp_optimizer_eager_test.py b/tensorflow_privacy/privacy/optimizers/dp_optimizer_eager_test.py index 7b4ccd1..22906b2 100644 --- a/tensorflow_privacy/privacy/optimizers/dp_optimizer_eager_test.py +++ b/tensorflow_privacy/privacy/optimizers/dp_optimizer_eager_test.py @@ -19,7 +19,6 @@ from __future__ import print_function from absl.testing import parameterized import numpy as np -from six.moves import range import tensorflow.compat.v1 as tf from tensorflow_privacy.privacy.dp_query import gaussian_query diff --git a/tensorflow_privacy/privacy/optimizers/dp_optimizer_test.py b/tensorflow_privacy/privacy/optimizers/dp_optimizer_test.py index fe89728..129f722 100644 --- a/tensorflow_privacy/privacy/optimizers/dp_optimizer_test.py +++ b/tensorflow_privacy/privacy/optimizers/dp_optimizer_test.py @@ -18,10 +18,10 @@ from __future__ import division from __future__ import print_function import os + from absl.testing import parameterized import mock import numpy as np -from six.moves import range import tensorflow.compat.v1 as tf from tensorflow_privacy.privacy.dp_query import gaussian_query diff --git a/tensorflow_privacy/privacy/optimizers/dp_optimizer_vectorized_test.py b/tensorflow_privacy/privacy/optimizers/dp_optimizer_vectorized_test.py index fb56095..e4d9633 100644 --- a/tensorflow_privacy/privacy/optimizers/dp_optimizer_vectorized_test.py +++ b/tensorflow_privacy/privacy/optimizers/dp_optimizer_vectorized_test.py @@ -20,7 +20,6 @@ from __future__ import print_function from absl.testing import parameterized import mock import numpy as np -from six.moves import range import tensorflow.compat.v1 as tf from tensorflow_privacy.privacy.optimizers import dp_optimizer_vectorized