<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _safe_minmax(values):
 """Calculate min and max of array with guards for nan and inf."""


    # Nan and inf guarded min and max
    isfinite = np.isfinite(values)
    if np.any(isfinite):
        # Only use finite values
        values = values[isfinite]

    minval = np.min(values)
    maxval = np.max(values)

    return minval, maxval