TheNeuralBit commented on a change in pull request #16615:
URL: https://github.com/apache/beam/pull/16615#discussion_r806077829



##########
File path: sdks/python/apache_beam/dataframe/transforms_test.py
##########
@@ -73,29 +74,52 @@ def df_equal_to(expected):
 
 
 class TransformTest(unittest.TestCase):
-  def run_scenario(self, input, func):
+  def run_scenario(self, input, func, check_subset=False):
+    """
+    In order for us to perform non-deferred operations, we have
+    to enumerate all possible categories, even if they are
+    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.
+
+    When ``check_subset`` is set to ``True``, we will only
+    check that all of the columns in the Pandas implementation is
+    contained in that of the Beam implementation.

Review comment:
       I misspoke, a column wth all 0s is what I'd expect in the Beam result. 
So sorry I sent you on this wild goose chase

##########
File path: 
website/www/site/content/en/documentation/dsls/dataframes/differences-from-pandas.md
##########
@@ -55,6 +55,35 @@ Beam DataFrame operations are deferred, but the schemas of 
the resulting DataFra
 
 Currently there’s no workaround for this issue. But in the future, Beam 
Dataframe may support non-deferred column operations on categorical columns. 
This work is being tracked in 
[BEAM-12169](https://issues.apache.org/jira/browse/BEAM-12169).
 
+We have started to implemented a few of these operations. So far the following 
have been implemented.

Review comment:
       :+1: thanks

##########
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

Review comment:
       ```suggestion
       Note: In order for us to perform non-deferred column operations in Beam, 
we have
   ```

##########
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

Review comment:
       nit: let's make this really clear it's a subset of columns
   ```suggestion
       If ``check_column_subset`` is `True`, we verify that all of the columns 
in the
   ```

##########
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:
       Apologies, in this case the columns in `actual` should be all 0s. I bet 
we'll want this value to be configurable for other operations that you're 
implementing, but we can hold off adding that until we need it.




-- 
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]


Reply via email to