def METHOD_NAME(weights: pd.DataFrame) -> pd.DataFrame:
    """
    Ensure that weights for ecah row sum up to one, except where all weights are zero
    Preserves nans
    >>> import datetime
    >>> df = pd.DataFrame(dict(a=[np.nan, np.nan, 0, 5,0, 2, 2], b=[0, np.nan, 0, np.nan,3,  3, 1]), index=pd.date_range(datetime.datetime(2000,1,1),periods=7))
    >>> weights_sum_to_one(df)
                       a         b
    2000-01-01       NaN  0.000000
    2000-01-02       NaN       NaN
    2000-01-03  0.000000  0.000000
    2000-01-04  1.000000       NaN
    2000-01-05  0.000000  1.000000
    2000-01-06  0.400000  0.600000
    2000-01-07  0.666667  0.333333
    """
    sum_weights = weights.sum(axis=1)
    zero_rows = sum_weights == 0.0
    sum_weights[zero_rows] = 0.0001  ## avoid Inf
    weight_multiplier = 1.0 / sum_weights
    weight_multiplier_array = np.array([weight_multiplier] * len(weights.columns))
    weight_values = weights.values
    normalised_weights_np = weight_multiplier_array.transpose() * weight_values
    normalised_weights = pd.DataFrame(
        normalised_weights_np, columns=weights.columns, index=weights.index
    )
    return normalised_weights