Repository navigation
Fix MICEData SettingWithCopyWarning on mixed-type dataframes - #5431
mattwigway wants to merge 5 commits into
Conversation
|
Thanks, this looks good. The CI has been broken for a long time. I don't know when we will be able to merge things again, but I'll merge this as soon as possible. |
|
The python 3.4 version on travis has a MICE related failure from this PR |
|
The error on Python 3.4 is from the test I added, looks like some warnings are being produced (not, I think, the warning I was trying to catch, but something else). I'll investigate further. |
|
I merged #5424, so travis with python 3.6 is also green on master. |
01d84ee to
20691ae
Compare
Codecov Report
@@ Coverage Diff @@
## master #5431 +/- ##
==========================================
- Coverage 82.03% 81.76% -0.28%
==========================================
Files 588 569 -19
Lines 93062 89859 -3203
Branches 10317 10022 -295
==========================================
- Hits 76345 73474 -2871
+ Misses 14355 14119 -236
+ Partials 2362 2266 -96
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #5431 +/- ##
==========================================
+ Coverage 82.03% 82.03% +<.01%
==========================================
Files 588 588
Lines 93062 93073 +11
Branches 10317 10318 +1
==========================================
+ Hits 76345 76356 +11
Misses 14355 14355
Partials 2362 2362
Continue to review full report at Codecov.
|
|
Hey, kinda forgot about this over Christmas, sorry. I just dug more into why the test was failing on Python 3.4 and confirmed it is unrelated to the SettingWithCopyWarning issue - there's a DeprecationWarning being raised which is I'm assuming you're not concerned about the deprecation warning that's only showing up on Python 3.4, so I just made the test ignore deprecation warnings. I also rebased my branch to latest master. I did put the existing master on a debugger and step through the code, and it appears that even with the existing code that the data is getting updated in spite of the SettingWithCopyWarning, but there's no guarantee that that would be true in every case, I think, so I think there could be a situation where the imputation does not work as intended with the current master because Let me know if there's anything I can do to help with the CI (if that's even still an issue), would love to see this merged so I don't have to work around it in my workflow. |
|
|
||
| with pd.option_context('mode.chained_assignment', 'warn'): | ||
| with warnings.catch_warnings(record=True) as ws: | ||
| warnings.simplefilter('always') |
There was a problem hiding this comment.
would pytest.mark.filterwarnings('ignore:pandas.core.common.is_categorical_dtype is deprecated:DeprecationWarning') work better? you might still be able to assert_no_warnings()?
You might be able to do...
@pytest.mark.filterwarnings('ignore:pandas.core.common.is_categorical_dtype is deprecated:DeprecationWarning')
def test_settingwithcopywarning(self):
df = gendat()
# There need to be some ints in here for the error to be thrown
df['intcol'] = np.arange(len(df))
df['intcol'] = df.intcol.astype('int32')
miceData = mice.MICEData(df)
with assert_no_warnings():
miceData.update_all()
There was a problem hiding this comment.
Good thought. I just tried that though and unfortunately it doesn't work - assert_no_warnings still fails (must be catching them below where pytest does its filtering).
I believe this should fix #5430; I have an automated test that passes, at least for integer dtypes.