yeandy commented on a change in pull request #16615:
URL: https://github.com/apache/beam/pull/16615#discussion_r803185070
##########
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:
Done! I add verification of the extra columns that don't exist in
`expected`. However, the extra columns from `get_dummies()`, based on my
current implementation, are `0`, not `NaN`. For example:
`actual` (Beam DF)
```
a b c d nan
3 0 0 1 0 0
0 1 1 0 0 0
2 0 0 0 0 1
1 0 0 0 0 1
```
`expected` (Pandas DF)
```
a b c nan
0 1 1 0 0
1 0 0 0 1
2 0 0 0 1
3 0 0 1 0
```
Is there a way to get `actual` to be this?
```
a b c d nan
3 0 0 1 NaN 0
0 1 1 0 NaN 0
2 0 0 0 NaN 1
1 0 0 0 NaN 1
```
## Resolution
I couldn't figure out a way to do this. Due to the way `get_dummies` creates
new columns, I had to call `fillna(0)`, but this means I won't be able to
preserve `NaN`. (Please see my `get_dummies` function)
Is there another trick that we can use to achieve this?
My previous try was with
```
lambda series: proxy.combine_first(
series.str.get_dummies(**kwargs)
).fillna(value=0, method=None).astype(int)
```
but it yields the same results as
```
lambda series: pd.concat(
[proxy, series.str.get_dummies(**kwargs)]
).fillna(value=0, method=None).astype(int),
```
--
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]