ihmeuw-msca / regmod

General regression models.
BSD 2-Clause "Simplified" License
5 stars 3 forks source link

Copy the prediction dataframe #63

Closed zhengp0 closed 1 year ago

zhengp0 commented 1 year ago

This PR aims to solve a warning message generated by pandas when tries to predict using the tobit class.

regmod/src/regmod/models/tobit.py:247: SettingWithCopyWarning: 
  A value is trying to be set on a copy of a slice from a DataFrame.
  Try using .loc[row_indexer,col_indexer] = value instead

  See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    df["mu_censored"] = df["mu"]

This issue is generated because we try to modify a slice or copy of the original data frame. To solve this we need to copy the original data frame passed into the predict function in the parent class.