yeandy commented on a change in pull request #17043:
URL: https://github.com/apache/beam/pull/17043#discussion_r831083595



##########
File path: sdks/python/apache_beam/dataframe/frames_test.py
##########
@@ -2209,6 +2209,112 @@ def test_nlargest_any(self):
     # but not necessarily with the same index
     self.assert_frame_data_equivalent(result, df.population.nlargest(3))
 
+  def test_pivot_non_categorical(self):
+    df = pd.DataFrame({
+        'foo': ['one', 'one', 'one', 'two', 'two', 'two'],
+        'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
+        'baz': [1, 2, 3, 4, 5, 6],
+        'zoo': ['x', 'y', 'z', 'q', 'w', 't']
+    })
+    with self.assertRaisesRegex(
+        frame_base.WontImplementError,
+        r"pivot\(\) of non-categorical type is not supported"):
+      self._evaluate(
+          lambda df: df.pivot(index='foo', columns='bar', values='baz'), df)
+
+  def test_pivot_pandas_example1(self):
+    # Simple test 1
+    df = pd.DataFrame({
+        'foo': ['one', 'one', 'one', 'two', 'two', 'two'],
+        'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
+        'baz': [1, 2, 3, 4, 5, 6],
+        'zoo': ['x', 'y', 'z', 'q', 'w', 't']
+    })
+    df['bar'] = df['bar'].astype(
+        pd.CategoricalDtype(categories=['A', 'B', 'C']))
+    result = self._evaluate(
+        lambda df: df.pivot(index='foo', columns='bar', values='baz'), df)
+    self.assert_frame_data_equivalent(
+        result, df.pivot(index='foo', columns='bar', values='baz'))
+
+  def test_pivot_pandas_example2(self):
+    # Simple test 2
+    df = pd.DataFrame({
+        'foo': ['one', 'one', 'one', 'two', 'two', 'two'],
+        'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
+        'baz': [1, 2, 3, 4, 5, 6],
+        'zoo': ['x', 'y', 'z', 'q', 'w', 't']
+    })
+    df['bar'] = df['bar'].astype(
+        pd.CategoricalDtype(categories=['A', 'B', 'C']))
+    result = self._evaluate(lambda df: df.pivot(index='foo', columns='bar'), 
df)
+    self.assert_frame_data_equivalent(
+        result['baz'], df.pivot(index='foo', columns='bar')['baz'])

Review comment:
       This test just selects the `baz` column, and the rest of `result` are 
non-zero, non-nans found in the `zoo` column. So there's no good verification 
to test. (unless we want to check that they are non-zero, non-nans?)

##########
File path: sdks/python/apache_beam/dataframe/frames_test.py
##########
@@ -2209,6 +2209,112 @@ def test_nlargest_any(self):
     # but not necessarily with the same index
     self.assert_frame_data_equivalent(result, df.population.nlargest(3))
 
+  def test_pivot_non_categorical(self):
+    df = pd.DataFrame({
+        'foo': ['one', 'one', 'one', 'two', 'two', 'two'],
+        'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
+        'baz': [1, 2, 3, 4, 5, 6],
+        'zoo': ['x', 'y', 'z', 'q', 'w', 't']
+    })
+    with self.assertRaisesRegex(
+        frame_base.WontImplementError,
+        r"pivot\(\) of non-categorical type is not supported"):
+      self._evaluate(
+          lambda df: df.pivot(index='foo', columns='bar', values='baz'), df)
+
+  def test_pivot_pandas_example1(self):
+    # Simple test 1
+    df = pd.DataFrame({
+        'foo': ['one', 'one', 'one', 'two', 'two', 'two'],
+        'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
+        'baz': [1, 2, 3, 4, 5, 6],
+        'zoo': ['x', 'y', 'z', 'q', 'w', 't']
+    })
+    df['bar'] = df['bar'].astype(
+        pd.CategoricalDtype(categories=['A', 'B', 'C']))
+    result = self._evaluate(
+        lambda df: df.pivot(index='foo', columns='bar', values='baz'), df)
+    self.assert_frame_data_equivalent(
+        result, df.pivot(index='foo', columns='bar', values='baz'))

Review comment:
       SG, moved!




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