Skip to content

Brittle Handling of failed utils/stats.kde(...) calls in utils/stats.df_percentile #1283

Closed
@CorbanSwain

Description

@CorbanSwain

err = True
while err:
try:
bandwidth, mesh, density, cdf = kde(inputData)
err = False
except:
logging.warning('Percentile computation failed. Duplicating ' + 'and trying again.')
if not isinstance(inputData, list):
inputData = inputData.tolist()
inputData += inputData

Given the broad catching of all exceptions; unexpected errors in kde(...) (i.e. any error not resolved by lengthening the input list) can lead to an infinite loop and exponential memory usage. I believe this was hanging Python when I encountered issue #1281 .

Example of my hotfix (but not necessarily to be duplicated) ... I think that the best solution would be to add the explicit exceptions intended to be caught when kde() fails after the except keyword.

def df_percentils(...):
   # ...
   if axis is not None:
      # ...
   else:
        RETRY_LIMIT = 16
        retry_count = 0
        err = True
        while err:
            try:
                bandwidth, mesh, density, cdf = kde(inputData)
                err = False
            except AttributeError:
                raise
            except:
                retry_count += 1
                if retry_count > RETRY_LIMIT:
                    raise

                logging.warning('Percentile computation failed. Duplicating ' + 'and trying again.')
                if not isinstance(inputData, list):
                    inputData = inputData.tolist()
                inputData += inputData

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions