Skip to content

More careful handling of masked values in FITS tables - #11222

Merged
mhvk merged 6 commits into
astropy:masterfrom
mhvk:io-fits-masked-columns
Jan 21, 2021
Merged

mhvk merged 6 commits into
astropy:masterfrom
mhvk:io-fits-masked-columns

Conversation

@mhvk

@mhvk mhvk commented Jan 7, 2021

Copy link
Copy Markdown
Contributor

As noted in #11194, writing masked float and string columns should be possible, by using np.nan and null string as null values, respectively, but this was broken in the transition of masked tables to tables able to contain MaskedColumn. This is fixed here (and improved, also fixing complex).

Furthermore, upon reading tables, those FITS null values are properly recognized and used to initialize a MaskedColumn.

I wasn't quite clear whether the latter should be labelled a bug or API change, but as I worried about breaking code in a bug-fix release, conservatively decided on API change, hence the 4.3 milestone. Obviously, happy to change this.

fixes #11194.

@mhvk mhvk added table io.fits Bug API change PRs and issues that change an existing API, possibly requiring a deprecation period labels Jan 7, 2021
@mhvk mhvk added this to the v4.3 milestone Jan 7, 2021
@github-actions github-actions Bot removed the table label Jan 7, 2021
@mhvk
mhvk force-pushed the io-fits-masked-columns branch from 0401075 to 58d0cb5 Compare January 7, 2021 20:59

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Some clarifications if needed.

finally:
hdulist.close()

# Check if table is masked

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought we should just do away with the masked table altogether, as it is more or less deprecated.

masked = mask = False
if col.null is not None:
mask = col.array == col.null
# Return a MaskedColumn even if no elements are masked so

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this make sense? Or should we always check if any masked values are present?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The current solution makes sense.

assert np.all(t['c2'].mask == np.array([False, False]))
assert np.all(t['c3'].mask == np.array([False, False]))
assert np.all(t['c4'].mask == np.array([False, False]))
assert not hasattr(t['c2'], 'mask')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A consequence of no longer returning a table with masked=True. I think worth it.

@mhvk

mhvk commented Jan 7, 2021

Copy link
Copy Markdown
Contributor Author

cc @taldcroft for the table link, @astrofrog for the fix needed for timeseries

@saimn saimn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A little comment about the changelog, otherwise seems good to me (and a very nice improvement) !

Comment thread CHANGES.rst Resolved
masked = mask = False
if col.null is not None:
mask = col.array == col.null
# Return a MaskedColumn even if no elements are masked so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The current solution makes sense.

@mhvk

mhvk commented Jan 17, 2021

Copy link
Copy Markdown
Contributor Author

Thanks! I'll use this opportunity to test the revived `[skip ci]' option...

@mhvk mhvk mentioned this pull request Jan 17, 2021

@saimn saimn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @mhvk, looks good to me. I will leave it open if @taldcroft or @astrofrog want to have a look.

@taldcroft taldcroft left a comment

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.

LGTM, thanks @mhvk!

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

Labels

API change PRs and issues that change an existing API, possibly requiring a deprecation period Bug io.fits

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants