beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [beam] branch master updated: Fix float coder test on Windows.
Date Sun, 02 Jun 2019 23:14:21 GMT
This is an automated email from the ASF dual-hosted git repository.

altay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new e21d28f  Fix float coder test on Windows.
     new 465784a  Merge pull request #8695 from robertwb/windows-float
e21d28f is described below

commit e21d28f5959c34cfa44822596d7b3c36d67ac874
Author: Robert Bradshaw <robertwb@google.com>
AuthorDate: Mon May 27 14:33:23 2019 +0200

    Fix float coder test on Windows.
---
 sdks/python/apache_beam/coders/standard_coders_test.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/sdks/python/apache_beam/coders/standard_coders_test.py b/sdks/python/apache_beam/coders/standard_coders_test.py
index 437d2be..c1ccac6 100644
--- a/sdks/python/apache_beam/coders/standard_coders_test.py
+++ b/sdks/python/apache_beam/coders/standard_coders_test.py
@@ -22,6 +22,7 @@ from __future__ import print_function
 
 import json
 import logging
+import math
 import os.path
 import sys
 import unittest
@@ -54,6 +55,15 @@ def _load_test_cases(test_yaml):
     yield [name, spec]
 
 
+def parse_float(s):
+  x = float(s)
+  if math.isnan(x):
+    # In Windows, float('NaN') has opposite sign from other platforms.
+    # For the purpose of this test, we just need consistency.
+    x = abs(x)
+  return x
+
+
 class StandardCodersTest(unittest.TestCase):
 
   _urn_to_json_value_parser = {
@@ -77,7 +87,7 @@ class StandardCodersTest(unittest.TestCase):
           lambda x, payload_parser: dict(
               payload=payload_parser(x['payload']),
               timestamp=Timestamp(micros=x['timestamp'] * 1000)),
-      'beam:coder:double:v1': lambda x: float(x),
+      'beam:coder:double:v1': parse_float,
   }
 
   def test_standard_coders(self):
@@ -88,7 +98,6 @@ class StandardCodersTest(unittest.TestCase):
   def _run_standard_coder(self, name, spec):
     def assert_equal(actual, expected):
       """Handle nan values which self.assertEqual fails on."""
-      import math
       if (isinstance(actual, float)
           and isinstance(expected, float)
           and math.isnan(actual)


Mime
View raw message