yeandy commented on a change in pull request #16615:
URL: https://github.com/apache/beam/pull/16615#discussion_r806954398
##########
File path: sdks/python/apache_beam/dataframe/frames_test.py
##########
@@ -1950,9 +1950,55 @@ class BeamSpecificTest(unittest.TestCase):
"""Tests for functionality that's specific to the Beam DataFrame API.
These features don't exist in pandas so we must verify them independently."""
- def assert_frame_data_equivalent(self, actual, expected):
+ def assert_frame_data_equivalent(
+ self, actual, expected, check_subset=False, extra_col_value=0):
"""Verify that actual is the same as expected, ignoring the index and order
- of the data."""
+ of the data.
+
+ Note: In order for us to perform non-deferred operations in Beam, we have
+ to enumerate all possible categories of data, even if they are ultimately
+ unobserved. The default Pandas implementation on the other hand does not
+ produce unobserved columns. This means when conducting tests, we need to
+ account for the fact that the Beam result may be a superset of that of the
+ Pandas result.
+
+ If ``check_subset`` is `True`, we verify that all of the columns in the
+ Dataframe returned from the Pandas implementation is contained in the
+ Dataframe created from the Beam implementation.
+
+ We also check if all columns that exist in the Beam implementation but
+ not in the Pandas implementation are all equal to the ``extra_col_value``
+ to ensure that they were not erroneously populated.
+ """
+ if check_subset:
+ if isinstance(expected, pd.DataFrame):
+ expected_cols = set(expected.columns)
+ actual_cols = set(actual.columns)
+ # Verifying that expected columns is a subset of the actual columns
+ if not set(expected_cols).issubset(set(actual_cols)):
+ raise AssertionError(
+ f"Expected columns:\n{expected.columns}\n is not a"
+ f"subset of {actual.columns}.")
+
+ # Verifying that columns that don't exist in expected
+ # are all NaN in actual
Review comment:
No worries; I forgot to change the wording in this comment. The logic
I've added supports configurable values, with `0` as the default value to which
the extra columns should be compared.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]