Skip to content
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

get_obs_products method supports product_type parameter as string or list #2995

Merged

Conversation

davidglt
Copy link
Contributor

The get_obs_products method now checks the input argument product_type with the method _check_list_strings and allows using strings or lists

@pep8speaks
Copy link

pep8speaks commented Apr 23, 2024

Hello @davidglt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-07-16 17:46:57 UTC

@jespinosaar
Copy link
Contributor

cc @esdc-esac-esa-int

@jespinosaar jespinosaar added this to the v0.4.8 milestone Apr 23, 2024
davidglt pushed a commit to esdc-esac-esa-int/astroquery that referenced this pull request Apr 25, 2024
davidglt pushed a commit to esdc-esac-esa-int/astroquery that referenced this pull request Apr 25, 2024
davidglt pushed a commit to esdc-esac-esa-int/astroquery that referenced this pull request Apr 25, 2024
davidglt pushed a commit to esdc-esac-esa-int/astroquery that referenced this pull request Apr 25, 2024
davidglt pushed a commit to esdc-esac-esa-int/astroquery that referenced this pull request Apr 25, 2024
@davidglt
Copy link
Contributor Author

Hi there!
The last commit 61b8b14 only modifies from the file in the main branch the lines to include this PR information, but maybe I have something more wrong :)
Cheers,
David

@jespinosaar
Copy link
Contributor

Hi @davidglt , please rebase your branch. It seems there is a conflict in CHANGES.rst file.

@davidglt
Copy link
Contributor Author

Hi there!
After rebase, we have the same problem with the CHANGES.rst file

Cheers,
David

@bsipocz
Copy link
Member

bsipocz commented May 3, 2024

I'm not exactly sure what went wrong with the rebase here, I suspect it might not been rebased on the correct branch. Given that there are new conflicts I do a rebase again and will report back the command history I will have used.

@bsipocz bsipocz force-pushed the ESA_jwst-extend_get_obs_products branch from 2d0bebd to 7b88527 Compare May 3, 2024 02:21
@bsipocz
Copy link
Member

bsipocz commented May 3, 2024

Given that there were a lot of incorrect edits for the changelog, I removed those commits during the rebase and instead added a single clean on once the rest has been rebased. Here are the commands:

Make sure you have the astropy/astroquery repo added as a git remote (I call this astropy in my setup, but it maybe upstream in yours):

$ ~/munka/devel/astroquery [ESA_jwst-extend_get_obs_products|✚ 1…1⚑ 14] $ git remote -v
astropy	[email protected]:astropy/astroquery.git (fetch)
astropy	[email protected]:astropy/astroquery.git (push)
bsipocz	[email protected]:bsipocz/astroquery.git (fetch)
bsipocz	[email protected]:bsipocz/astroquery.git (push)
esdc-esac-esa-int	[email protected]:esdc-esac-esa-int/astroquery (fetch)
esdc-esac-esa-int	[email protected]:esdc-esac-esa-int/astroquery (push)

Have a fresh version of the main repo:

git fetch --all --prune

Interactive rebase on astropy/main. This will automatically get rid of the ~80 commits that you pulled in during the previous rebase. Also, in the interactive mode an editor will pop up. I removed all commits related to the changelog. The rebase was clean, I didn't need to resolve any conflicts, but if there are any, you read the instructions and do --continue until all commits are successfully rebased.

git rebase -i astropy/main

Once the rebase is done, I edited the changelog file and added that commit.

Now, the important part (which might have been the step that didn't worked previously) is to force push the branch back to github. I call the ESAC fork push esdc-esac-esa-int, you may have it as origin.

git push esdc-esac-esa-int HEAD:ESA_jwst-extend_get_obs_products -f

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

Please add a test that covers the list case for product_type input. Also see the inline comments as I suspect the a bug, but also suggest a shorter solution for the enhancement.

@@ -83,6 +83,15 @@ def __init__(self, *, tap_plus_handler=None, data_handler=None, show_messages=Tr
if show_messages:
self.get_status_messages()

def __check_list_strings(self, list):
Copy link
Member

Choose a reason for hiding this comment

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

I would strongly advise calling the parameter something else than list to avoid overriding the list()

def __check_list_strings(self, list):
if list is None:
return False
if list and all(isinstance(elem, str) for elem in list):
Copy link
Member

Choose a reason for hiding this comment

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

a single string is iterable and this will return True, is that the logic you want to do here?

Comment on lines 1006 to 1013

if self.__check_list_strings(product_type):
if type(product_type) is list:
tap_product_type = ",".join(str(elem) for elem in product_type)
else:
tap_product_type = product_type
else:
tap_product_type = None
Copy link
Member

Choose a reason for hiding this comment

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

this function is only used in this one place, so I would instead suggest something in-place here along the line of the following few line. Arguably this doesn't gracefully handle the case when the input list is not full of strings, but the docs calls for strings, so duct-typeing should be sufficient. And with this the extra private function is not needed either.

Suggested change
if self.__check_list_strings(product_type):
if type(product_type) is list:
tap_product_type = ",".join(str(elem) for elem in product_type)
else:
tap_product_type = product_type
else:
tap_product_type = None
if isinstance(product_type, list):
tap_product_type = ",".join(str(elem) for elem in product_type)
elif isinstance(product_type, str):
tap_product_type = product_type
else:
tap_product_type = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brigitta, thank you very much for your comments and patience!
I was not using the --force in the push, my fault :)
About this method "check_list_strings" is used as in other submodules (ex. hubble), but you’re right, in jwst no, I can delete it and check the entries directly in "get_obs_products".
Cheers,
David

@bsipocz
Copy link
Member

bsipocz commented May 3, 2024

Also, @davidglt - if you add the email address you made the commits with to your github profile, these commits will properly show up as your contributions.

@davidglt davidglt force-pushed the ESA_jwst-extend_get_obs_products branch from 7b88527 to 6e9dfbd Compare May 6, 2024 07:57
@davidglt
Copy link
Contributor Author

davidglt commented May 6, 2024

Hi Brigitta, I am working to implement a new test for the product_type parameter as string or list

@davidglt
Copy link
Contributor Author

Hi Brigitta,
I've included a remote-test in docs/esa/jwst/jwst.rst with product_type as a list.
Do you need anything else?

Thanks!
David

@jespinosaar
Copy link
Contributor

Thanks @davidglt! we still need to include the entry in the changelog.

@bsipocz
Copy link
Member

bsipocz commented May 20, 2024

Do you need anything else?

I'm travelling in the coming week so PR reviews and merges may be delayed. Sorry about that.
With a quick look at the changes, I see that a test is still missing (# doctest: +SKIP skips running the code example). And the changelog changes will need to be squashed, but I'm more than happy to do that once I'm back in Seattle.

@davidglt davidglt force-pushed the ESA_jwst-extend_get_obs_products branch from 78d03ec to d7bcbbc Compare May 21, 2024 08:32
@davidglt
Copy link
Contributor Author

Hi Brigitta,
Now we have a green light! maybe the interpreter was confused :)
I learned a lot from your suggestions!
Cheers,
David

@davidglt
Copy link
Contributor Author

Hi Brigitta,
Do you need anything more?
Cheers,
David

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

Please add a test for product_type being a list.

astroquery/esa/jwst/core.py Outdated Show resolved Hide resolved
astroquery/esa/jwst/core.py Outdated Show resolved Hide resolved
@jespinosaar
Copy link
Contributor

jespinosaar commented Jun 18, 2024

Please add a test for product_type being a list.

Hi @davidglt , I will help you with the test.

@davidglt
Copy link
Contributor Author

davidglt commented Jul 2, 2024

Hello!
We have just implemented your two recommendations:

  1. Replace "type(product_type is list" with isinstance(product_type, list)
  2. Improve comments on the get_obs_products method for the output parameter

Cheers,
David

@davidglt
Copy link
Contributor Author

davidglt commented Jul 2, 2024

Please add a test for product_type being a list.

We have done an online test in docs/esa/jwst/jwst.rst, do you want an offline test too or is that enough?
Cheers,
David

@davidglt
Copy link
Contributor Author

davidglt commented Jul 8, 2024

Please add a test for product_type being a list.

We have done an online test in docs/esa/jwst/jwst.rst, do you want an offline test too or is that enough? Cheers, David

Hi Brigitta,
test offline for product_type as a list in test_get_obs_products included.
Cheers,
David

@jespinosaar
Copy link
Contributor

jespinosaar commented Jul 8, 2024

Hi @bsipocz , I have seen the test is now included. I have checked it and seems to be working. The issue with the CI seems to be unrelated. Thanks @davidglt

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

Some minor comments about the tests, happy to merge as is and leave that for a future cleanup, or wait here.

@@ -997,10 +1000,16 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
max_cal_level=max_cal_level,
is_url=True)
params_dict['planeid'] = plane_ids

if type(product_type) is list:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if type(product_type) is list:
if isinstance(product_type, list):

@@ -733,6 +733,37 @@ def test_get_obs_products(self):
finally:
shutil.rmtree(output_file_full_path_dir)

# Test product_type paramater with a list
output_file_full_path_dir = os.getcwd() + os.sep + "temp_test_jwsttap_get_obs_products_1"
Copy link
Member

Choose a reason for hiding this comment

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

I see that all these are inherited from above, so these are generic cleanup comments, not necessary to address them for merging this particular PR:

  • os.path.join does this much nicer than creating the output string like this.
  • the try except below is not really necessary for the tests. If the test fail with OSError, then I presume the developer/maintainer knows how to read the traceback.
  • It may be worth to do parametrization of the product_type instead of copying practically the same code (e.g. look for the usage of pytest.mark.parametrize in e.g the esasky tests)
  • overall, it is better if tests are made smaller, so e.g. here if there is copied code, it may instead land in a separate test as opposed to be added after an already existing one.

@jespinosaar
Copy link
Contributor

Hi @bsipocz ,
Many thanks for your feedback! We will be cleaning the code for all ESA modules in a different pull request, so maybe we can merge this PR and then create another one with changes for all of them. What do you think?

@bsipocz
Copy link
Member

bsipocz commented Jul 16, 2024

@jespinosaar - Yes, that sounds good to me. I'll rebase to fix the conflict, and then merge this one as is.

@bsipocz bsipocz force-pushed the ESA_jwst-extend_get_obs_products branch from d0f7e1a to bb734e0 Compare July 16, 2024 17:46
@bsipocz bsipocz merged commit 08ff1b8 into astropy:main Jul 16, 2024
8 checks passed
@bsipocz
Copy link
Member

bsipocz commented Jul 16, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants