Skip to content

ENH: Make no unshare mask future warnings less noisy - #7187

Closed
seberg wants to merge 1 commit into
numpy:masterfrom
seberg:blah
Closed

seberg wants to merge 1 commit into
numpy:masterfrom
seberg:blah

Conversation

@seberg

@seberg seberg commented Feb 4, 2016

Copy link
Copy Markdown
Member

Also fixes a small bug in flat setting (which is utterly broken
in any case though)

Comment thread numpy/ma/extras.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thought I would remove it, unshare mask does nothing except setting _sharedmask to false, since the mask is overwritten anyway. Removing this means that the __setitem__ call to unshare_mask is the only remaining call in numpy. Coupld possibly be deprecated itself when this is done.

@seberg seberg changed the title ENH: Make future warnings less noisy ENH: Make no unshare mask future warnings less noisy Feb 4, 2016
Comment thread numpy/ma/core.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I should leave this, the result changing based on sharedmask seems nonsense, but it does change behaviour once in a while. On the other hand we would have to futurewarn this on its own.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, removed this fix for now, to be "minimal". Als omaybe the warning gives at least some hint of the weird behaviour that goes on and it will be automatically fixed with the other stuff. (only the sharedmask bug, not the one about non-contiguous arrays).

Comment thread numpy/ma/core.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tihs line could in principle change a result, if you do something crazy like:

arr = masked_arr[[0, 1, 2, 3]]  # not a view
view = arr[::2]
arr[4] = 5.  # will change view with change, triggers copy without change
view2 = arr[::4]  # view after
arr[6] = 6.  # would change view2, since copy was triggered.

so maybe could undo so that a warning is given. The logic is designed to avoid back propagation to the parent, since that creates copies at an arbitrary later time, it can do do weird things.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I guess I could undo this, in favor of doing that slightly silly refcount + owndata check below, which should find it. I think I will do that.

Comment thread numpy/ma/core.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the private attribute is ugly, but the only way I can think of. Silencing the warning even more, seems only possible by starting to do reference count checks (i.e. refcount of mask == 1 and it has no base -> no copy necessary)

@seberg

seberg commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

@njsmith you seem to have an overview who got hit hard by this, can you maybe ask them if this helps enough? It reduces the numpy tests failures to around 15 or so, it might clear up almost all things, or maybe they use masked views a lot and it is still extremely noisy....

@seberg

seberg commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

I will fix the numpy "test failures" by setting that attribute or slencing them in my warnings cleanup PR.

@njsmith

njsmith commented Feb 5, 2016

Copy link
Copy Markdown
Member

@njsmith you seem to have an overview who got hit hard by this, can you maybe ask them if this helps enough?

Basically what I know is that I ran the statsmodels and matplotlib test suites against master and counted the warnings :-) Something like

virtualenv testenv
testenv/bin/pip install path/to/numpy statsmodels nose
testenv/bin/python -c "import statsmodels.api as sm; sm.test()" 2>&1 | tee statsmodels.log
git clone matplotlib/matplotlib
cd matplotlib
../testenv/bin/python setup.py build_ext -i
../testenv/bin/python tests.py 2>&1 | tee ../matplotlib.log
cd ..
grep "masked array" statsmodels.log | wc -l
grep "masked array" matplotlib.log | wc -l

@seberg

seberg commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

That means I have to figure out how to run statsmodels nose ;). I made the changes more minimal by checking the refcounts now, I think this is about as good as it can in the sense of minimal invasive and as fully precise warning.

@njsmith

njsmith commented Feb 5, 2016

Copy link
Copy Markdown
Member

@seberg: That's why I just told you how to run statsmodels's tests :-P

@charris charris added this to the 1.11.0 release milestone Feb 5, 2016
@seberg

seberg commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

I never let fact go into the way of my reasoning :p. Don't get any warnings with this applied, but maybe my quick hack test (or statsmodel version 0.5.0) were wrong/not sensitive. Saw only 2 with master? I had the impression I should see more.

@seberg

seberg commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

OK, I had to add an "always" filter and now on master (I guess it might be different with python -c). Then I see the spam. Anyway, it is fully gone with this applied -> statsmodels is clean (which makes sense, the errors may even have come from inside numpy, which uses masked arrays sometimes for small nanfuncs).

Hmmm, some wheel issue with f2py cropped up in the test, seems unrelated.

@charris

charris commented Feb 5, 2016

Copy link
Copy Markdown
Member

Yeah, the latest venv release (5 in two weeks) with yet another setuptools upgrade is probably responsible. Grrr, we may just need to pin setuptools at some point. Or nuke it from orbit.

Comment thread numpy/ma/core.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big warning without line breaks, it would be better if it was shorter with maybe a reference to the release notes for extended explanation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do it (with release notes changes), but I am not the best writer for this stuff....

Also fixes a small bug in flat setting (which is utterly broken
in any case though)
@homu

homu commented Feb 9, 2016

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7194) made this pull request unmergeable. Please resolve the merge conflicts.

@charris charris removed this from the 1.11.0 release milestone Feb 9, 2016
@charris

charris commented Feb 9, 2016

Copy link
Copy Markdown
Member

@seberg I went with #7194 for b3.

@seberg

seberg commented Feb 10, 2016

Copy link
Copy Markdown
Member Author

Sure, though it might be good to have a quick look here whether there is something that was missed before release.

@seberg

seberg commented Feb 21, 2016

Copy link
Copy Markdown
Member Author

@charris, Chuck, should I have a look at this today? I think at least the corrcoef fix still needs to be put in. Sorry if this is annoying you. It would be nice if someone who is not me can decide if some of the other differences should be put in. I don't want to assert my opinion here, but also feel it likely did not get the careful check it should have....

@njsmith

njsmith commented Feb 21, 2016

Copy link
Copy Markdown
Member

@seberg: I haven't had the time and attention to follow all these details properly, so I would certainly feel better knowing that you have checked it over :-)

@seberg

seberg commented Feb 28, 2016

Copy link
Copy Markdown
Member Author

Closing this for gh-7363, but feel free to close it if nobody cares anymore. This is my last bid at giving a shit, this is masked arrays after all. Giving the warning for something like np.nanmedian(np.full(10, np.nan).reshape(5, 2), axis=1) is pretty evil though ;).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants