[ 
https://issues.apache.org/jira/browse/BEAM-12560?focusedWorklogId=693520&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-693520
 ]

ASF GitHub Bot logged work on BEAM-12560:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Dec/21 19:51
            Start Date: 09/Dec/21 19:51
    Worklog Time Spent: 10m 
      Work Description: TheNeuralBit commented on a change in pull request 
#15827:
URL: https://github.com/apache/beam/pull/15827#discussion_r766105964



##########
File path: sdks/python/apache_beam/dataframe/frames.py
##########
@@ -1277,6 +1277,74 @@ def align(self, other, join, axis, level, method, 
**kwargs):
       requires_partition_by=partitionings.Arbitrary(),
       preserves_partition_by=partitionings.Singleton())
 
+  @frame_base.with_docs_from(pd.Series)
+  @frame_base.args_to_kwargs(pd.Series)
+  @frame_base.populate_defaults(pd.Series)
+  def idxmin(self, **kwargs):
+    def compute_idxmin(s):
+      min_index = s.idxmin(**kwargs)
+      if pd.isna(min_index):
+        return s
+      else:
+        return s.loc[[min_index]]
+
+    # Avoids empty Series error when evaluating proxy
+    index_dtype = self._expr.proxy().index.dtype
+    index = pd.Index([], dtype=index_dtype)
+    proxy = self._expr.proxy().copy()
+    proxy.index = index
+    proxy = proxy.append(
+        pd.Series([np.inf], index=np.asarray(['0']).astype(proxy.index.dtype)))
+
+    idx_min = expressions.ComputedExpression(
+        'idx_min',
+        compute_idxmin, [self._expr],
+        proxy=proxy,
+        requires_partition_by=partitionings.Index(),
+        preserves_partition_by=partitionings.Arbitrary())
+
+    with expressions.allow_non_parallel_operations(True):
+      return frame_base.DeferredFrame.wrap(
+          expressions.ComputedExpression(
+              'idxmin_combine',
+              lambda s: s.idxmin(**kwargs), [idx_min],
+              requires_partition_by=partitionings.Singleton(),
+              preserves_partition_by=partitionings.Singleton()))
+
+  @frame_base.with_docs_from(pd.Series)
+  @frame_base.args_to_kwargs(pd.Series)
+  @frame_base.populate_defaults(pd.Series)
+  def idxmax(self, **kwargs):
+    def compute_idxmax(s):
+      max_index = s.idxmax(**kwargs)
+      if pd.isna(max_index):
+        return s
+      else:
+        return s.loc[[max_index]]
+
+    # Avoids empty Series error when evaluating proxy
+    index_dtype = self._expr.proxy().index.dtype
+    index = pd.Index([], dtype=index_dtype)
+    proxy = self._expr.proxy().copy()
+    proxy.index = index
+    proxy = proxy.append(
+        pd.Series([-np.inf], 
index=np.asarray(['0']).astype(proxy.index.dtype)))
+
+    idx_max = expressions.ComputedExpression(
+        'idx_max',
+        compute_idxmax, [self._expr],
+        proxy=proxy,
+        requires_partition_by=partitionings.Index(),

Review comment:
       I reproduced the error in `pandas_doctests_test.py`, the message is:
   ```
   Failed example:                                                              
                                                                                
                 
       s.idxmin()                                                               
          
   Expected:                                                                    
                                                                                
                 
       'A'                                                                      
                                                                                
                 
   Got:                                                                         
                                                                                
                 
       'A'
   ```
   
   This looks like an issue with the test framework, and not an actual bug. Can 
you just skip the failing cases with a comment about this? The cases 
(s.idxmin(), s.idxmax()) seem to be covered in frames_test.py anyway




-- 
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: 693520)
    Time Spent: 8h  (was: 7h 50m)

> Implement idxmin and idxmax for DataFrame, Series, and GroupBy
> --------------------------------------------------------------
>
>                 Key: BEAM-12560
>                 URL: https://issues.apache.org/jira/browse/BEAM-12560
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-dataframe
>            Reporter: Brian Hulette
>            Assignee: Mike Hernandez
>            Priority: P3
>          Time Spent: 8h
>  Remaining Estimate: 0h
>
> Add an implementation of 
> [idxmin|https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmin.html]
>  and 
> [idxmax|https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmax.html]
>  for DeferredDataFrame, DeferredSeries, and DeferredGroupBy. It should be 
> fully unit tested with some combination of pandas_doctests_test.py and 
> frames_test.py.
> https://github.com/apache/beam/pull/14274 is an example of a typical PR that 
> adds new operations. See 
> https://lists.apache.org/thread.html/r8ffe96d756054610dfdb4e849ffc6a741e826d15ba7e5bdeee1b4266%40%3Cdev.beam.apache.org%3E
>  for background on the DataFrame API.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to