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

Added observations/species_counts endpoint #55

Merged
merged 3 commits into from
Sep 25, 2020
Merged

Conversation

willkuhn
Copy link
Contributor

Added two new functions get_observations_species_counts and get_all_observations_species_counts that utilize the iNaturalist API observations/species_counts endpoint (https://api.inaturalist.org/v1/docs/#!/Observations/get_observations_species_counts). I needed these and thought others might find them useful as well.

I hope this is helpful!

@JWCook
Copy link
Member

JWCook commented Sep 23, 2020

@willkuhn Thanks for the contribution! We just need a couple changes to the PR before merging this in.

It looks like you branched off of the master branch rather than the dev branch, and there are some merge conflicts. Coincidentally, a get_observation_species_counts() was already added in PR #44 . Your get_all_observations_species_counts() would be a good addition to that, though. Instead of resolving merge conflicts one at a time, it would probably be easiest to make a new branch off of dev and add your get_all_observations_species_counts() there.

Then, the new function needs a unit test. See test/test_node_api.py for examples. This and a few other guidelines are mentioned in the Contributing guide.

If you would like help with any of that, let me know. I would probably have time to add tests for this later this week if needed.

@JWCook JWCook added the new endpoint Add a new API endpoint label Sep 23, 2020
@willkuhn
Copy link
Contributor Author

@JWCook Thanks for the feedback and apologies for not following directions! I think I'm in the straight and narrow now...

I've forked the dev now and added get_all_observations_species_counts() and an appropriate unit test. My updates passed the pytest. All good so far.

I am having trouble getting the docs to rebuild with tox though. I keep getting "ValueError: Received multiple parameters with name 'user_agent'". It builds correctly when I comment out my function, so it's definitely the culprit, but I cannot figure out how to solve this error on my own. I'll paste the full traceback below and maybe something will jump out.

I went ahead and created a commit to my fork with the changes that I've made so far. I would be grateful if you're about to provide any suggestions for how to fix this! Apart from that, I'm ready to PR this baby.

My fork: https://github.com/willkuhn/pyinaturalist

Traceback:

Traceback (most recent call last):
File "/mnt/d/Dropbox/dev/pyinaturalist/.tox/docs/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 66, in import_module
return importlib.import_module(modname)
File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/mnt/d/Dropbox/dev/pyinaturalist/pyinaturalist/node_api.py", line 187, in
def get_all_observation_species_counts(user_agent: str = None, **kwargs) -> List[JsonResponse]:
File "/mnt/d/Dropbox/dev/pyinaturalist/pyinaturalist/forge_utils.py", line 59, in f
func = copy_signatures(func, template_functions)
File "/mnt/d/Dropbox/dev/pyinaturalist/pyinaturalist/forge_utils.py", line 121, in copy_signatures
return revision(target_function)
File "/mnt/d/Dropbox/dev/pyinaturalist/.tox/docs/lib/python3.7/site-packages/forge/revision.py", line 330, in call
next
.validate()
File "/mnt/d/Dropbox/dev/pyinaturalist/.tox/docs/lib/python3.7/site-packages/forge/_signature.py", line 1328, in validate
format(current.name)
ValueError: Received multiple parameters with name 'user_agent'

@JWCook
Copy link
Member

JWCook commented Sep 25, 2020

@willkuhn

I think that error isn't necessarily your fault, it seems to be caused by something within the @document_request_params decorator, which I added recently and may still have a few quirks to work out.

I checked out your fork, and if I comment out that decorator from both get_observation_species_counts() and get_all_observation_species_counts() (lines 157 & 186), then both the unit tests and the documentation builds will pass. I'd say go ahead and just comment out those lines for now (which will only affect documentation), and I can merge this in and look into that issue some more afterward.

By the way, you may already know this, but you can overwrite your original branch in-place so you don't have to open a separate PR:

# Rename the local patch-1 branch
git checkout patch-1
git branch -m patch-1-backup

# Overwrite the remote patch-1 branch with the contents of dev
git checkout dev
git checkout -b patch-1
git push --force --set-upstream origin patch-1

Thanks!

@willkuhn
Copy link
Contributor Author

Ok, I commented out those 2 lines and also added an Example for get_all_observation_species_counts() with an Example Response. Unit tests passed and doc build passed. 👍

I don't really know what I'm doing with the git command line, so I just followed your instructions exactly and it appeared to force-push successfully. But it looks like ci checked failed though, so was it actually a success?

Thanks for all your guidance to a noob!

@JWCook
Copy link
Member

JWCook commented Sep 25, 2020

99% success! You can see the logs on Travis CI. The only part that failed was the black check: https://travis-ci.org/github/niconoe/pyinaturalist/jobs/730241072#L325

You can appease it by running black . locally and then committing the changes.

@JWCook JWCook merged commit b8567ed into pyinat:dev Sep 25, 2020
@JWCook JWCook added this to the v0.11 milestone Sep 25, 2020
@JWCook
Copy link
Member

JWCook commented Sep 25, 2020

Your changes are now available in the latest dev build on pypi, pyinaturalist==0.11.0.dev320; and they will be in the next stable release, which I hope to finish within the next 4-6 weeks.

Thanks again for the contribution!

@JWCook
Copy link
Member

JWCook commented Sep 30, 2020

@willkuhn Fyi, the issue you ran into above A) was definitely my fault 🤦, and B) has been fixed in PR #61. Those changes are now in the latest dev build as well (0.11.0.dev335).

@JWCook
Copy link
Member

JWCook commented Nov 4, 2020

@willkuhn FYI, these changes are now available in the latest stable release.

@willkuhn willkuhn deleted the patch-1 branch January 8, 2021 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new endpoint Add a new API endpoint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Observation species counts endpoint from Node API
2 participants