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
Solving issue with wcs.wcs.cunit equality #8480
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8480 +/- ##
==========================================
- Coverage 86.79% 86.76% -0.03%
==========================================
Files 386 386
Lines 58098 58117 +19
Branches 1060 1065 +5
==========================================
Hits 50427 50427
- Misses 7056 7075 +19
Partials 615 615
Continue to review full report at Codecov.
|
This will need testing, as a minimal one e.g. the example from the issue would do. |
Codecov Report
@@ Coverage Diff @@
## master #8480 +/- ##
==========================================
- Coverage 86.82% 86.81% -0.01%
==========================================
Files 386 386
Lines 58197 58213 +16
Branches 1060 1064 +4
==========================================
+ Hits 50530 50540 +10
- Misses 7052 7054 +2
- Partials 615 619 +4
Continue to review full report at Codecov.
|
I added test for wcs.cunit @bsipocz Thanks for helping |
Another wcs is added in test_wcs.py thanks for suggestion @astrofrog |
Thanks for the contribution. I found it quite hard to read the code because it doesn't follow the coding conventions in the rest of the file (nor PEP 7). Could you please re-format the code (especially with regards to whitespaces, indentation, and blank lines) to follow the style of the rest of the file? |
astropy/wcs/src/unit_list_proxy.c
Outdated
Py_RETURN_FALSE; | ||
} | ||
} else { | ||
return NULL; |
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.
Returning NULL
without an exception will probably result in a SystemError
- or is that handled differently for richcmp
? Did you check this path?
By the way I would prefer it to immediately fail in case an exception should be raised. That way one could also remove the status
variable completely.
astropy/wcs/src/unit_list_proxy.c
Outdated
if (self->size!=other->size||self->unit_class!=other->unit_class||self->array!=other->array) | ||
{status = 0; | ||
equal = 0;} | ||
else if (self == 0x0 || other == 0x0){ |
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.
0x0
? Do you mean NULL
?
astropy/wcs/src/unit_list_proxy.c
Outdated
PyObject_TypeCheck(other, &PyUnitListProxyType)) { | ||
|
||
|
||
if (self->size!=other->size||self->unit_class!=other->unit_class||self->array!=other->array) |
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 think this is correct to use pointer equality for unit_class
or array
. Are these singletons?
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 felt so that they are singletons. I will check it again
Thank you for the pull request. I have some questions about the changes but I'm not really familiar with the WCS C-internals so forgive me if these may sound stupid. 😄 Btw: a first-time contributor that dares to go into Python C Extensions - I'm genuinely impressed! 👍 Let me know if you need any help or my comments don't make sense to you. |
astropy/wcs/src/unit_list_proxy.c
Outdated
@@ -4,6 +4,8 @@ | |||
*/ | |||
|
|||
#define NO_IMPORT_ARRAY | |||
#ifndef ASTROPY_WCS_API_H | |||
#define ASTROPY_WCS_API_H |
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.
Not sure if this is correct. As far as I see this constant should be defined only in astropy_wcs_api.h
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.
Yes I am removing this. It is not correct
The flake check did detect some problems in the Python file too:
Could you fix them so the CI can succeed? |
@MSeifert04 I need help I can't able to find any method to convert PyObject to C type for comparison . |
@himanshupathak21061998 I'm not sure what you mean with |
@MSeifert04 Sorry for late reply but I was not able to find any good way to compare |
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.
Thanks for the update. This looks really good.
The indentation still seems to be a bit off though and I have some comments (again).
astropy/wcs/src/unit_list_proxy.c
Outdated
@@ -16,6 +16,7 @@ | |||
|
|||
static PyTypeObject PyUnitListProxyType; | |||
|
|||
|
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 think the additional blank line is needed
astropy/wcs/src/unit_list_proxy.c
Outdated
@@ -186,6 +187,59 @@ PyUnitListProxy_getitem( | |||
return result; | |||
} | |||
|
|||
static PyObject * | |||
PyUnitListProxy_richcmp( | |||
PyUnitListProxy *a, |
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.
By assuming PyUnitListProxy
here instead of PyObject
(see richcmpfunc
) we might get segfaults if you compare them to non PyUnitListProxy
. (could you add a test case for a different class?)
@himanshupathak21061998 Thanks for the update, this looks really good 👍
If
No problem. By the way: I'm away the next few days and probably cannot reply until next Tuesday. 😅 |
@pllim Sorry for pinging you - but are the test failures expected? They seem unrelated but I haven't been really active in the past so I don't know 😓 |
@MSeifert04 , I just saw these errors on another PR and also on cron (https://travis-ci.org/astropy/astropy/jobs/506241000). Will have to investigate but I don't think they are related to this PR. UPDATE: Failures are unrelated and caused by #8498 |
@pllim Thank you for the investigation. 👍 I was on the mobile and did not want to look at the travis logs (because they tend to load for a while) and forgot when I came home. 😅 |
Not sure for the cause of error https://ci.appveyor.com/project/Astropy/astropy/builds/23131678 |
@himanshupathak21061998 Do you let me know when the comments are addressed so I can do a final review (although @nden probably needs to do the final review/approval). |
@MSeifert04 I am struggling with this
Because when I accept Pyobject and compare Objects inside PyUnitListProxy struct. It always returning true can you please suggest a way to tackle this |
The static PyObject *
PyUnitListProxy_richcmp(
PyObject *a,
PyObject *b,
int op) { Because we don't want to compare them to anything else except other PyUnitListProxy *lhs, *rhs;
/* Normally these shouldn't be NULL, ever */
assert(a != NULL && b != NULL);
/* At the moment we only support comparisons of PyUnitListProxy with other instances of the same class */
if (!PyObject_TypeCheck(a, &PyUnitListProxyType)
|| !PyObject_TypeCheck(b, &PyUnitListProxyType) {
Py_RETURN_NOTIMPLEMENTED;
}
/* Only equality and non-equality are supported */
if (op != Py_EQ && op != Py_NE)) {
Py_RETURN_NOTIMPLEMENTED;
}
lhs = (PyUnitListProxy *)a;
rhs = (PyUnitListProxy *)b; Then continue with For example I would then immediately check if int equal = PyObject_RichCompareBool(lhs->unit_class, rhs->unit_class, Py_EQ);
if (equal == -1) {
return NULL; // Exception will be set because the rich-compare failed
} and so on. I tend to prefer failing immediately because it avoids deep (and complex) nestings later. |
391223b
to
ad51a36
Compare
@MSeifert04 thanks for helping I added all things as suggested by you. Sorry for late updates |
@MSeifert04 Now should I squash commits. If everything is done |
@himanshupathak21061998 I'll do another review later today. Thanks for the update |
@MSeifert04 Please review changes |
@himanshupathak2106199 - please be patient, all core maintainers have different day jobs than maintaining astropy, so having to wait a couple of days (or weeks in cases) for a review is part of the game. |
Sorry for the long delay, I've been a bit busy. This looks good to me (from a technical viewpoint), the changelog could be clarified a bit though. @astrofrog or @nden what do you think? |
98ce78d
to
b80fce8
Compare
@MSeifert04 Thanks for reviewing and helping me I have changed the Changelog.rst |
@himanshupathak21061998 This looks good! Thanks for the contribution and sorry for the late review. I am not sure what the codecov report means. It looks like it points to files in @himanshupathak21061998 can you squash the commits? |
b80fce8
to
2d2501b
Compare
@nden Thanks for reviewing I have done with squashing the commits as suggested |
Again Codecov failure😁 |
@himanshupathak21061998 Could you add tests for
I hope this will solve the coverage issue. |
2d2501b
to
9478ea0
Compare
9478ea0
to
9a91f69
Compare
# Inequality checking of cunit with a list of literals | ||
assert not w1.wcs.cunit == [1, 2, 3] | ||
# Inequality checking with some characters | ||
assert w1.wcs.cunit != ['a', 'b', 'c'] |
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 added this test because of !=
lhs = (PyUnitListProxy *)a; | ||
rhs = (PyUnitListProxy *)b; | ||
int equal = PyObject_RichCompareBool(lhs->unit_class, rhs->unit_class, Py_EQ); | ||
if (equal == -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.
Coverage report failure is because of this case as PyObject_RichCompareBool
is not returning -1 in any of the case present in the test. For this I think, it needs direct testing of PyUnitListProxy
which will be more cumbersome. So right now we can merge it
@nden Can you please review it again Thanks for helping |
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.
Thanks @himanshupathak21061998 ! I am going to merge this as it is.
Thanks for merging |
EDIT: Fix #8415
Please Help me out in this after a lot reading from here and there I was able to apply this because Embedded c with python is a new topic for me. So, please forgive any mistakes done by me .
__eq__
function was not working so I used richcompare function