PEtab-dev / libpetab-python

Python package for working with PEtab files
https://libpetab-python.readthedocs.io
MIT License
14 stars 5 forks source link

pandas FutureWarning: Setting an item of incompatible dtype is deprecated #224

Closed dweindl closed 9 months ago

dweindl commented 10 months ago

With pandas 2.1.0:

    petab.lint_problem(petab_problem)
/home/runner/.local/lib/python3.9/site-packages/petab/lint.py:888: in lint_problem
    errors_occurred |= validate_visualization_df(problem)
/home/runner/.local/lib/python3.9/site-packages/petab/visualize/lint.py:39: in validate_visualization_df
    _apply_defaults(vis_df)
/home/runner/.local/lib/python3.9/site-packages/petab/visualize/lint.py:131: in _apply_defaults
    set_default(C.PLOT_TYPE_DATA, C.MEAN_AND_SD)
/home/runner/.local/lib/python3.9/site-packages/petab/visualize/lint.py:127: in set_default
    vis_df[column].fillna(value, inplace=True)
/home/runner/.local/lib/python3.9/site-packages/pandas/core/generic.py:7210: in fillna
    new_data = self._mgr.fillna(
/home/runner/.local/lib/python3.9/site-packages/pandas/core/internals/base.py:173: in fillna
    return self.apply_with_block(
/home/runner/.local/lib/python3.9/site-packages/pandas/core/internals/managers.py:354: in apply
    applied = getattr(b, f)(**kwargs)
/home/runner/.local/lib/python3.9/site-packages/pandas/core/internals/blocks.py:1415: in fillna
    nbs = self.putmask(mask.T, value, using_cow=using_cow)
/home/runner/.local/lib/python3.9/site-packages/pandas/core/internals/blocks.py:1232: in putmask
    return self.coerce_to_target_dtype(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = NumpyBlock: 7 dtype: float64, other = 'MeanAndSD', warn_on_upcast = True

    @final
    def coerce_to_target_dtype(self, other, warn_on_upcast: bool = False) -> Block:
        """
        coerce the current block to a dtype compat for other
        we will return a block, possibly object, and not raise

        we can also safely try to coerce to the same dtype
        and will receive the same block
        """
        new_dtype = find_result_type(self.values.dtype, other)

        # In a future version of pandas, the default will be that
        # setting `nan` into an integer series won't raise.
        if (
            is_scalar(other)
            and is_integer_dtype(self.values.dtype)
            and isna(other)
            and other is not NaT
        ):
            warn_on_upcast = False
        elif (
            isinstance(other, np.ndarray)
            and other.ndim == 1
            and is_integer_dtype(self.values.dtype)
            and is_float_dtype(other.dtype)
            and lib.has_only_ints_or_nan(other)
        ):
            warn_on_upcast = False

        if warn_on_upcast:
>           warnings.warn(
                f"Setting an item of incompatible dtype is deprecated "
                "and will raise in a future error of pandas. "
                f"Value '{other}' has dtype incompatible with {self.values.dtype}, "
                "please explicitly cast to a compatible dtype first.",
                FutureWarning,
                stacklevel=find_stack_level(),
            )
E           FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value 'MeanAndSD' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.