@@ -419,14 +419,27 @@ def pandas_groupby_nan(df, by, axis=0, as_index=False, suffix=None, nanback=True
419419 res .grouper .groupings [0 ]._group_index = Index (new_val )
420420 res .grouper .groupings [0 ].obj [b ].replace (
421421 fnan , numpy .nan , inplace = True )
422- if isinstance (res .grouper .groupings [0 ].grouper , numpy .ndarray ):
423- arr = numpy .array (new_val )
424- res .grouper .groupings [0 ].grouper = arr
425- if hasattr (res .grouper .groupings [0 ], '_cache' ) and 'result_index' in res .grouper .groupings [0 ]._cache :
426- del res .grouper .groupings [0 ]._cache ['result_index' ]
422+ if hasattr (res .grouper , 'grouping' ):
423+ if isinstance (res .grouper .groupings [0 ].grouper , numpy .ndarray ):
424+ arr = numpy .array (new_val )
425+ res .grouper .groupings [0 ].grouper = arr
426+ if (hasattr (res .grouper .groupings [0 ], '_cache' ) and
427+ 'result_index' in res .grouper .groupings [0 ]._cache ):
428+ del res .grouper .groupings [0 ]._cache ['result_index' ]
429+ else :
430+ raise NotImplementedError ("Not implemented for type: {0}" .format (
431+ type (res .grouper .groupings [0 ].grouper )))
427432 else :
428- raise NotImplementedError ("Not implemented for type: {0}" .format (
429- type (res .grouper .groupings [0 ].grouper )))
433+ grouper = res .grouper ._get_grouper ()
434+ if isinstance (grouper , numpy .ndarray ):
435+ arr = numpy .array (new_val )
436+ res .grouper .groupings [0 ].grouping_vector = arr
437+ if (hasattr (res .grouper .groupings [0 ], '_cache' ) and
438+ 'result_index' in res .grouper .groupings [0 ]._cache ):
439+ res .grouper .groupings [0 ]._cache = {}
440+ else :
441+ raise NotImplementedError ("Not implemented for type: {0}" .format (
442+ type (res .grouper .groupings [0 ].grouper )))
430443 res .grouper ._cache ['result_index' ] = res .grouper .groupings [0 ]._group_index
431444 else :
432445 if not nanback :
0 commit comments