From 16f72eaac4b99be6bc2e67a96c3c33b0def64aae Mon Sep 17 00:00:00 2001 From: Matthias Feys Date: Fri, 11 May 2018 13:45:49 +0200 Subject: [PATCH] Futurize metrics subpackage --- sdks/python/apache_beam/metrics/__init__.py | 2 ++ sdks/python/apache_beam/metrics/cells.py | 15 +++++++++++++++ sdks/python/apache_beam/metrics/cells_test.py | 3 +++ sdks/python/apache_beam/metrics/execution.py | 10 ++++++++++ sdks/python/apache_beam/metrics/execution_test.py | 3 +++ sdks/python/apache_beam/metrics/metric.py | 3 +++ sdks/python/apache_beam/metrics/metric_test.py | 3 +++ sdks/python/apache_beam/metrics/metricbase.py | 4 ++++ sdks/python/tox.ini | 1 + 9 files changed, 44 insertions(+) diff --git a/sdks/python/apache_beam/metrics/__init__.py b/sdks/python/apache_beam/metrics/__init__.py index 8ce7bbb173fd..e74168f09e4b 100644 --- a/sdks/python/apache_beam/metrics/__init__.py +++ b/sdks/python/apache_beam/metrics/__init__.py @@ -14,5 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from __future__ import absolute_import + from apache_beam.metrics.metric import Metrics from apache_beam.metrics.metric import MetricsFilter diff --git a/sdks/python/apache_beam/metrics/cells.py b/sdks/python/apache_beam/metrics/cells.py index 302d79ab5127..8f93d7fffe5e 100644 --- a/sdks/python/apache_beam/metrics/cells.py +++ b/sdks/python/apache_beam/metrics/cells.py @@ -23,10 +23,13 @@ Cells depend on a 'dirty-bit' in the CellCommitState class that tracks whether a cell's updates have been committed. """ + +from __future__ import absolute_import from __future__ import division import threading import time +from builtins import object from google.protobuf import timestamp_pb2 @@ -245,6 +248,9 @@ def __eq__(self, other): else: return False + def __hash__(self): + return hash(self.data) + def __ne__(self, other): return not self.__eq__(other) @@ -292,6 +298,9 @@ def __eq__(self, other): else: return False + def __hash__(self): + return hash(self.data) + def __ne__(self, other): return not self.__eq__(other) @@ -326,6 +335,9 @@ def __init__(self, value, timestamp=None): def __eq__(self, other): return self.value == other.value and self.timestamp == other.timestamp + def __hash__(self): + return hash((self.value, self.timestamp)) + def __ne__(self, other): return not self.__eq__(other) @@ -386,6 +398,9 @@ def __eq__(self, other): self.min == other.min and self.max == other.max) + def __hash__(self): + return hash((self.sum, self.count, self.min, self.max)) + def __ne__(self, other): return not self.__eq__(other) diff --git a/sdks/python/apache_beam/metrics/cells_test.py b/sdks/python/apache_beam/metrics/cells_test.py index 14e7e537ea1c..64b9df95bbfb 100644 --- a/sdks/python/apache_beam/metrics/cells_test.py +++ b/sdks/python/apache_beam/metrics/cells_test.py @@ -15,8 +15,11 @@ # limitations under the License. # +from __future__ import absolute_import + import threading import unittest +from builtins import range from apache_beam.metrics.cells import CellCommitState from apache_beam.metrics.cells import CounterCell diff --git a/sdks/python/apache_beam/metrics/execution.py b/sdks/python/apache_beam/metrics/execution.py index cb0f07141a11..157fa0aaf5e1 100644 --- a/sdks/python/apache_beam/metrics/execution.py +++ b/sdks/python/apache_beam/metrics/execution.py @@ -29,7 +29,11 @@ - MetricsContainer - Holds the metrics of a single step and a single unit-of-commit (bundle). """ + +from __future__ import absolute_import + import threading +from builtins import object from collections import defaultdict from apache_beam.metrics.cells import CounterCell @@ -59,6 +63,9 @@ def __eq__(self, other): return (self.step == other.step and self.metric == other.metric) + def __hash__(self): + return hash((self.step, self.metric)) + def __repr__(self): return 'MetricKey(step={}, metric={})'.format( self.step, self.metric) @@ -98,6 +105,9 @@ def __eq__(self, other): self.committed == other.committed and self.attempted == other.attempted) + def __hash__(self): + return hash((self.key, self.committed, self.attempted)) + def __repr__(self): return 'MetricResult(key={}, committed={}, attempted={})'.format( self.key, str(self.committed), str(self.attempted)) diff --git a/sdks/python/apache_beam/metrics/execution_test.py b/sdks/python/apache_beam/metrics/execution_test.py index 37d24f3407bc..fbf5492f05d6 100644 --- a/sdks/python/apache_beam/metrics/execution_test.py +++ b/sdks/python/apache_beam/metrics/execution_test.py @@ -15,7 +15,10 @@ # limitations under the License. # +from __future__ import absolute_import + import unittest +from builtins import range from apache_beam.metrics.cells import CellCommitState from apache_beam.metrics.execution import MetricsContainer diff --git a/sdks/python/apache_beam/metrics/metric.py b/sdks/python/apache_beam/metrics/metric.py index 8b6c50f9e9f8..3ff132bee4a9 100644 --- a/sdks/python/apache_beam/metrics/metric.py +++ b/sdks/python/apache_beam/metrics/metric.py @@ -24,7 +24,10 @@ - Metrics - This class lets pipeline and transform writers create and access metric objects such as counters, distributions, etc. """ +from __future__ import absolute_import + import inspect +from builtins import object from apache_beam.metrics.execution import MetricsEnvironment from apache_beam.metrics.metricbase import Counter diff --git a/sdks/python/apache_beam/metrics/metric_test.py b/sdks/python/apache_beam/metrics/metric_test.py index 84f6ae910480..0cd492f77b44 100644 --- a/sdks/python/apache_beam/metrics/metric_test.py +++ b/sdks/python/apache_beam/metrics/metric_test.py @@ -15,7 +15,10 @@ # limitations under the License. # +from __future__ import absolute_import + import unittest +from builtins import object from apache_beam.metrics.cells import DistributionData from apache_beam.metrics.execution import MetricKey diff --git a/sdks/python/apache_beam/metrics/metricbase.py b/sdks/python/apache_beam/metrics/metricbase.py index 2ef9fe6d5350..2453f41c9545 100644 --- a/sdks/python/apache_beam/metrics/metricbase.py +++ b/sdks/python/apache_beam/metrics/metricbase.py @@ -32,6 +32,10 @@ - MetricName - Namespace and name used to refer to a Metric. """ +from __future__ import absolute_import + +from builtins import object + from apache_beam.portability.api import beam_fn_api_pb2 __all__ = ['Metric', 'Counter', 'Distribution', 'Gauge', 'MetricName'] diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index caa899de2dbe..61dc12c3017a 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -99,6 +99,7 @@ deps = flake8==3.5.0 modules = apache_beam/coders + apache_beam/metrics commands = python --version pip --version