Skip to content

Table MaskedColumn updating issues #2997

Closed

Description

@cdeil

@taldcroft Can you please look at example 1 and 3 in this notebook?
http://nbviewer.ipython.org/gist/cdeil/69b79c04b2477dbf611a

Is this a bug in the masked table implementation?

If not, can you point me to or add documentation how one can update missing data in Astropy tables?
I did look through the docs a bit, but couldn't find it.

Naively this is what I tried ... it results in a table where the mask is in a weird (corrupt?) state:

# Try to update missing information in column `b` from column `c`
mask = t['b'].mask
t['b'][mask] = t['c'][mask]

While looking through the docs I saw this section which explained that rows are views for non-masked tables, but copies for masked tables. That's another bug I had in my script. Aargh ... I'm thinking of re-writing my script completely using pandas.DataFrame instead, in the hope that it will let me process my data with missing values more easily.

Activity

  1. astrofrog commented on Sep 30, 2014

    @astrofrog
    Member

    @cdeil - that seems like a bug, so labeling it as such

  2. mhvk commented on Sep 30, 2014

    @mhvk
    Contributor

    @cdeil - masked tables are still a source of problems -- some resulting from papering over underlying issues in MaskedArray -- but to at least have something while this is investigated: in astropy.utils.iers.IERS_A, the following does work:

            table['UT1_UTC'] = np.where(table['UT1_UTC_B'].mask,
                                        table['UT1_UTC_A'].data,
                                        table['UT1_UTC_B'].data)
    

    (the need for the .data is due to a numpy 1.9 bug; numpy/numpy#5095)

  3. taldcroft commented on Sep 30, 2014

    @taldcroft
    Member

    Yes, it's a bug. It may not be consolation to you at the moment, but this is apparently fixed by the Table refactor that I'm currently working on (#2790, which I just converted to a PR). This refactor removes the underlying MaskedArray, which I suspect is part of the problem here. Here is your notebook using the #2790 branch:

    http://nbviewer.ipython.org/gist/taldcroft/04842c847193579a5bab

  4. cdeil commented on Sep 30, 2014

    @cdeil
    MemberAuthor

    OK, thanks for confirming that it's a bug ... it was driving me mad this morning.
    I'm surprised no-one has has run into this behaviour before and that it's not covered by a unit test.
    @taldcroft Thanks for fixing this in #2790.

  5. cdeil commented on Sep 30, 2014

    @cdeil
    MemberAuthor

    I've filed two feature requests that I think would have helped me debug my script much faster (but are really generally useful, I think): #2998 and #2999.

  6. taldcroft commented on Oct 1, 2014

    @taldcroft
    Member

    I marked this as fixed when #2790 gets merged, but we'll leave it open until then. I'll be sure to add tests for this case.

  7. cdeil commented on Dec 1, 2016

    @cdeil
    MemberAuthor

    I re-ran the notebook that shows the bug again with Astropy master:
    http://nbviewer.jupyter.org/gist/cdeil/a33b8925fe6b0f9fba410175a3ccbf18

    As far as I can see, the behaviour and results are OK not, and this issue can be closed.
    @taldcroft or @mhvk - Can you please double-check?

    The one thing is that there's this warning:

    /Users/deil/Library/Python/3.5/lib/python/site-packages/astropy/table/column.py:1096: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
    Check the NumPy 1.11 release notes for more information.
      ma.MaskedArray.__setitem__(self, index, value)
    

    Is it possible to change something in astropy/table/column.py:1096 so that the code works with old / new Numpy and doesn't emit this warning?

    I marked this as fixed when #2790 gets merged, but we'll leave it open until then. I'll be sure to add tests for this case.

    Is a test case in place?

  8. saimn commented on Dec 1, 2016

    @saimn
    Contributor

    For MaskedArrayFutureWarning see #5060: the behavior has not changed yet. I think it will be changed in Numpy 1.13 but I cannot find the related issue.

  9. mhvk commented on Dec 1, 2016

    @mhvk
    Contributor

    The relevant numpy issues is numpy/numpy#5580
    Bottom line: in the future, both data and mask get shared for views. I made a new issue to keep track of that (#5530), but @saimn correctly points out that #5060 already exists. We should move discussion of the warning there.

    Anyway, for this issue, we can ignore the warnings, which, I think, means it can be closed (I confirmed that the original example now works). So, I'll do that!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions