-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ds9 reader corrections/improvements #90
Conversation
is what ds9 actually uses for rectangles), adding a warning if the region isn't recognized, and allowing for whitespace (which ds9 can handle)
@keflavich - Thanks! Long-term I think an option to "ignore", "warn" or "error" on this would be best, like what the Python unicode encode / decode functions do. For now: can you please add one test for one case where the warning is raised, asserting that it works? |
maybe kwarg should be |
I like That's what Python uses for
and
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a AstropyUserWarning
appropriate for parsing errors? Shouldn't it be a more specific DS9RegionParsingError
to make it more obvious and easier to handle in other libraries?
@@ -192,20 +194,33 @@ def ds9_region_list_to_objects(region_list): | |||
else: | |||
raise ValueError("No central coordinate") | |||
else: | |||
# Note: this should effectively never happen, because it would |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will happen all the time. People have invalid ds9
files and region_type
. They mistype or whatever.
Can you change this code comment from "this should effectively never happen, ..." to something like "For invalid inputs, we do ..."
Is it possible to give the user a line number where the problem in their file occurs?
It will be really common and users will appreciate a helpful message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this error actually can't occur by user error. If a user mistypes / enters an incorrect region type, the previous function, ds9_string_to_region_list
, should fail. Only regions that are parsed by ds9_string_to_region_list
but do not have a corresponding entry within ds9_region_list_to_objects
should reach this point, and that should only happen if someone updating this code forgets to add a new entry in this function.
"""Parse ds9 region string to region objects | ||
|
||
Parameters | ||
---------- | ||
region_string : str | ||
DS9 region string | ||
warn_skipped : bool | ||
Print a warning if there is a skipped (commented) line? | ||
Can set to ``False`` or ``'raise'`` if you want an exception instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said in the other comment, I'd prefer to call it "error".
And as-is, the option is documented as bool
, but you also accept a string raise
.
That's no good.
Let's make it a multi-choice string option.
@@ -357,6 +385,19 @@ def line_parser(line, coordsys=None): | |||
language_spec[region_type] = itertools.chain((coordinate, coordinate), itertools.cycle((radius,))) | |||
|
|||
return region_type, parsed_return, parsed_meta, composite, include | |||
else: | |||
# it is not clear when it is OK to warn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we resolve / improve the discussion on when to warn in this PR, and then change the comment?
It currently reads as an open issue "it is not clear ..."
Maybe just put whatever behaviour you like best, and establish it via tests?
fyi, I'm pushing failing builds because I can't run tests locally; they all raise: |
If you can't figure it out, maybe try |
I can't figure it out, the problem persists, but I can run the tests directly now with
|
@cdeil I think this is ready for final review now |
@astrofrog or @joleroi - Do you have time for a quick review here? |
I think it's good that you introduce a specific For equivalent errors, should we stick with |
from ..write_ds9 import write_ds9, ds9_objects_to_string | ||
|
||
_ASTROPY_MINVERSION = v.LooseVersion('1.1') | ||
_ASTROPY_VERSION = v.LooseVersion(astrov.version) | ||
_ASTROPY_MINVERSION = vers.LooseVersion('1.1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are working towards putting this as astropy.regions
in the core package.
So there's no need to support old Astropy versions.
At the moment regions
has to work with Astropy 1.2, and we can switch to 1.3 as soon as that is out.
So remove this xfail
for Astropy < 1.1 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason to remove the xfail now, as long as regions
is still an independent package. Sure, when we merge it into astropy-core, then it makes sense... but that's not now.
I like the idea of adding a |
I'm merging this now. Thanks, @keflavich ! |
Mostly minor: