[
https://issues.apache.org/jira/browse/BEAM-12169?focusedWorklogId=727306&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-727306
]
ASF GitHub Bot logged work on BEAM-12169:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 15/Feb/22 18:39
Start Date: 15/Feb/22 18:39
Worklog Time Spent: 10m
Work Description: 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]
Issue Time Tracking
-------------------
Worklog Id: (was: 727306)
Time Spent: 6h 20m (was: 6h 10m)
> Allow non-deferred column operations on categorical columns
> -----------------------------------------------------------
>
> Key: BEAM-12169
> URL: https://issues.apache.org/jira/browse/BEAM-12169
> Project: Beam
> Issue Type: Improvement
> Components: dsl-dataframe, sdk-py-core
> Reporter: Brian Hulette
> Assignee: Andy Ye
> Priority: P3
> Labels: dataframe-api
> Time Spent: 6h 20m
> Remaining Estimate: 0h
>
> There are several operations that we currently disallow because they produce
> a variable set of columns in the output based on the data
> (non-deferred-columns). However, for some dtypes (categorical, boolean) we
> can easily enumerate all the possible values that will be seen at execution
> time, so we can predict the columns that will be seen.
> Note we still can't implement these operations 100% correctly, as pandas will
> typically only create columns for the values that are _observed_, while we'd
> have to create a column for every possible value.
> We should allow these operations in these special cases.
> Operations in this category:
> - DataFrame.unstack (can work if unstacked level is a categorical or boolean
> column)
> - Series.str.get_dummies
> - Series.str.split
> - Series.str.rsplit
> - DataFrame.pivot
> - DataFrame.pivot_table
> - len(GroupBy) and ngroups
> ** if groupers are all categorical _and_ observed=False or all boolean
> ** Note these two may not actually be equivalent in all cases:
> [https://github.com/pandas-dev/pandas/issues/26326]
--
This message was sent by Atlassian Jira
(v8.20.1#820001)