Skip to content

Raise more informative exception in Table value formatting if type and format mismatch#3055

Closed
cherti wants to merge 7 commits intoastropy:masterfrom
cherti:issue2868
Closed

Raise more informative exception in Table value formatting if type and format mismatch#3055
cherti wants to merge 7 commits intoastropy:masterfrom
cherti:issue2868

Conversation

@cherti
Copy link
Copy Markdown
Contributor

@cherti cherti commented Oct 26, 2014

Implementing Issue #2868:

Implementing raising TypeError upon nonworking format string instead of value error, handling it above the point where it was originally raised to include information about the exact point of failure.

Additionally getter and setter were implemented to raise the error as soon as it can be determined to not work (aka when setting it).

Format is checked for all existing entries in case of np.object-ish and for one entry for other types as this should be sufficient and more efficient for large tables.

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.

Here you can just do:

raise

(no need for the TypeError...) - and this way you preserve the traceback

@mhvk mhvk changed the title Issue2868 Raise more informative exception in Table value formatting if type and format mismatch Nov 11, 2014
@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Nov 11, 2014

@cherti - I renamed your PR with a more informative title -- feel free to change if it doesn't quite capture what you want.

@cdeil
Copy link
Copy Markdown
Member

cdeil commented Dec 11, 2014

@cherti There's test errors on travis-ci:
https://travis-ci.org/astropy/astropy/jobs/39160458#L1927

Are you able to reproduce and debug those locally by running this?

python setup.py test -P table -V

Also there's merge conflicts ... could you please rebase this pull request against master?

@cherti
Copy link
Copy Markdown
Contributor Author

cherti commented Dec 13, 2014

Actually I currently have a problem with even a freshly cloned astropy being unable to run all the tests without throwing an Exception(*). Unfortunately I haven't had the time to debug this one, therefore I cannot test my stuff.

I'll do the rebase as soon as I figured out the weird issue with the testing. If there wasn't that, I'd have this Pull Request finished for merge, however, I hadn't had enough time up to now to fully debug the error with the tests as it seems a little weird to me and I haven't figured out completely what's going wrong. I think there is no point in doing the rebase now if I cannot run the tests, is there? Sorry for the delay.

*) ImportError: /tmp/astropy-test-96ydtnmh/lib.linux-x86_64-3.4/astropy/utils/_compiler.cpython-34m.so: failed to map segment from shared object

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.

I'm not exactly clear what this line is supposed to do--is this just checking that the dtype is object? As is this will always return False--type() returns a class, and you're just comparing that class to a bunch of strings.

embray added a commit to embray/astropy that referenced this pull request Dec 30, 2014
Column implementation in master.  This also made a few changes to
methods like __array_finalize__ and __setstate__ to not go through the
setters for name, unit, and format--these are copying/recreating
Columns from existing objects that should presumably already have valid
values for those attributes.

This also addresses my comment on the original PR here:
astropy#3055 (comment)

Finally, in order for this to pass testing several existing tests needed
to be updated, now that we no longer allow a Column with an invalid
format to be created in the first place (a change I support).
@embray embray mentioned this pull request Dec 30, 2014
embray added a commit to embray/astropy that referenced this pull request Dec 30, 2014
Column implementation in master.  This also made a few changes to
methods like __array_finalize__ and __setstate__ to not go through the
setters for name, unit, and format--these are copying/recreating
Columns from existing objects that should presumably already have valid
values for those attributes.

This also addresses my comment on the original PR here:
astropy#3055 (comment)

Finally, in order for this to pass testing several existing tests needed
to be updated, now that we no longer allow a Column with an invalid
format to be created in the first place (a change I support).
@cherti
Copy link
Copy Markdown
Contributor Author

cherti commented Dec 30, 2014

@embray
Oh, you are right, my mistake, sorry. My intention was to check if the type is applicable to the first element of the column, because that way I could verify that the format will work on every entry without looping over the entire column, which might have an unnecessary performance-impact depending on the size of the column.
However, this does only work if the column contains elements of same types. The ones in the list are those types (and to my best knowledge all of them, but I probably missed some) that do not guarantee that and therefore are not applicable for first-element-checking to verify that the format works.
If this is the case, the format is tested against all entries of the column (as there is no better possibility to ensure it works on all entries).

Does that clarify what I intended in that line?

@embray
Copy link
Copy Markdown
Member

embray commented Dec 31, 2014

@cherti Somewhat...I think...it would be helpful if you added a regression test that exemplifies exactly the situation. From the sound of it though I think that additional check can be removed pretty much entirely.

@cherti cherti closed this Jul 31, 2015
embray added a commit to embray/astropy that referenced this pull request Aug 19, 2015
Column implementation in master.  This also made a few changes to
methods like __array_finalize__ and __setstate__ to not go through the
setters for name, unit, and format--these are copying/recreating
Columns from existing objects that should presumably already have valid
values for those attributes.

This also addresses my comment on the original PR here:
astropy#3055 (comment)

Finally, in order for this to pass testing several existing tests needed
to be updated, now that we no longer allow a Column with an invalid
format to be created in the first place (a change I support).
bsipocz pushed a commit to bsipocz/astropy that referenced this pull request Jul 21, 2017
Column implementation in master.  This also made a few changes to
methods like __array_finalize__ and __setstate__ to not go through the
setters for name, unit, and format--these are copying/recreating
Columns from existing objects that should presumably already have valid
values for those attributes.

This also addresses my comment on the original PR here:
astropy#3055 (comment)

Finally, in order for this to pass testing several existing tests needed
to be updated, now that we no longer allow a Column with an invalid
format to be created in the first place (a change I support).
bsipocz pushed a commit to bsipocz/astropy that referenced this pull request Aug 11, 2017
Column implementation in master.  This also made a few changes to
methods like __array_finalize__ and __setstate__ to not go through the
setters for name, unit, and format--these are copying/recreating
Columns from existing objects that should presumably already have valid
values for those attributes.

This also addresses my comment on the original PR here:
astropy#3055 (comment)

Finally, in order for this to pass testing several existing tests needed
to be updated, now that we no longer allow a Column with an invalid
format to be created in the first place (a change I support).
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.

6 participants