udim commented on a change in pull request #14568:
URL: https://github.com/apache/beam/pull/14568#discussion_r620557014



##########
File path: sdks/python/apache_beam/dataframe/schemas_test.py
##########
@@ -36,6 +36,8 @@
 from apache_beam.testing.test_pipeline import TestPipeline
 from apache_beam.testing.util import assert_that
 from apache_beam.testing.util import equal_to
+from apache_beam.typehints import typehints
+from apache_beam.typehints.native_type_compatibility import 
_match_is_named_tuple

Review comment:
       nit: remove the leading underscore since `_match_is_named_tuple` is no 
longer private.

##########
File path: sdks/python/apache_beam/dataframe/schemas_test.py
##########
@@ -203,19 +223,32 @@ def test_batch_with_df_transform(self):
                 proxy=schemas.generate_proxy(Animal)))
         assert_that(res, equal_to([('Falcon', 375.), ('Parrot', 25.)]))
 
+  def assert_typehints_equal(self, left, right):
+    left = typehints.normalize(left)
+    right = typehints.normalize(right)
+
+    if _match_is_named_tuple(left):
+      self.assertTrue(_match_is_named_tuple(right))
+      self.assertEqual(left.__annotations__, right.__annotations__)
+    else:
+      self.assertEqual(left, right)
+
   @parameterized.expand(SERIES_TESTS + NOINDEX_DF_TESTS)
-  def test_unbatch_no_index(self, df_or_series, rows):
+  def test_unbatch_no_index(self, df_or_series, rows, beam_type):
     proxy = df_or_series[:0]
 
     with TestPipeline() as p:
       res = (
           p | beam.Create([df_or_series[::2], df_or_series[1::2]])
           | schemas.UnbatchPandas(proxy))
 
+      # Verify that the unbatched PCollection has the expected typehint
+      self.assert_typehints_equal(res.element_type, beam_type)

Review comment:
       Does `self.assertTrue(typehints.is_consistent_with(res.element_type, 
beam_type))` work here? Do you need assert_typehints_equal because 
typing.NamedTuples get converted to Any? If so, could you reference 
https://issues.apache.org/jira/browse/BEAM-8538 here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to