cdisc-org / cdisc-rules-engine

Open source offering of the cdisc rules engine
MIT License
46 stars 12 forks source link

present_on_multiple_rows_within fails for a single group #599

Open ASL-rmarshall opened 9 months ago

ASL-rmarshall commented 9 months ago

If present_on_multiple_rows_within is used and the data contains only one group of values in the variable specified in within (and possibly if there are multiple groups all with the same number of records), validation fails with the following error:

'DataFrame' object has no attribute 'tolist'

This error occurs because the data structure produced by groupby() is upcast to a DataFrame if all groups are the same length. Conditionally using stack() may prevent this error:

        results = grouped.apply(lambda x: self.validate_series_length(x, target, min_count))
        if not isinstance(results,pd.Series):
            results = results.stack()