File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -3356,10 +3356,20 @@ def _nunique(self, skipna=True):
3356
3356
:class:`swat.CASResults`
3357
3357
If By groups are specified.
3358
3358
'''
3359
- # If we have a groupby table, we will have multiple tables in our CASResults
3359
+ # If we have a groupby table, we need to flatten down to one DataFrame
3360
3360
if self .get_groupby_vars ():
3361
- # Just return the CASResults object
3362
- return self ._retrieve ('simple.distinct' , includeMissing = not skipna )
3361
+ distinct_results = self ._retrieve ('simple.distinct' , includeMissing = not skipna )
3362
+ distinct_results .pop ('ByGroupInfo' , None )
3363
+ # Same bygroups flattening as CASTable.nmiss
3364
+ out = pd .concat (list (distinct_results .values ()))
3365
+ out = out .set_index ('Column' , append = True )['NDistinct' ]
3366
+ out = out .unstack (level = - 1 )
3367
+ out = out .astype ('int64' )
3368
+ # The columns that match the groupby vars will be useless
3369
+ out = out .drop (labels = self .get_groupby_vars (), axis = 1 )
3370
+ if isinstance (out , pd .DataFrame ):
3371
+ out .columns .name = None
3372
+ return out
3363
3373
else :
3364
3374
distinct_table = self ._retrieve ('simple.distinct' ,
3365
3375
includeMissing = not skipna )['Distinct' ]
You can’t perform that action at this time.
0 commit comments