Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #40 from EcoJulia/bugfix/fullrequest
Browse files Browse the repository at this point in the history
Fix an edge case bug when the limit was left blank
  • Loading branch information
tpoisot authored Feb 27, 2021
2 parents 3f22bd4 + f4a2477 commit cdd2690
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
10 changes: 1 addition & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GBIF"
uuid = "ee291a33-5a6c-5552-a3c8-0f29a1181037"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.3.2"
version = "0.3.3"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -14,11 +14,3 @@ HTTP = "0.8, 0.9"
JSON = "0.21"
Requires = "1.0"
julia = "1.3"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "DataFrames", "Query"]
2 changes: 1 addition & 1 deletion src/paging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function _internal_limit_update!(o::GBIFRecords)
limit_index = findfirst((p) -> string(p.first) == "limit", o.query)
limit = isnothing(limit_index) ? 20 : o.query[limit_index].second
if (length(o) + limit) > size(o)
deleteat!(o.query, limit_index)
isnothing(limit_index) || deleteat!(o.query, limit_index)
push!(o.query, "limit" => size(o) - length(o))
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/requires/dataframes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@info "Loading DataFrames support for GBIF.jl"

format_gbif_entity(t::Missing) = missing
format_gbif_entity(::Missing) = missing
format_gbif_entity(t::Pair{String,Int64}) = t.first

import .DataFrames: DataFrame
Expand Down
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
43 changes: 29 additions & 14 deletions test/occurrences.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
module TestGBIFRecords

using GBIF
using Test
using GBIF
using Test

# Version using pairs
set1 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true)
@test typeof(set1) == GBIFRecords
@test length(set1) == 20
# Version using pairs
set1 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true)
@test typeof(set1) == GBIFRecords
@test length(set1) == 20

# Version with no query parameters
set2 = occurrences()
@test typeof(set2) == GBIFRecords
@test length(set2) == 20
# Version with no query parameters
set2 = occurrences()
@test typeof(set2) == GBIFRecords
@test length(set2) == 20

# Version using ranged pairs
set3 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true, "decimalLatitude" => (0.0,50.0))
@test typeof(set3) == GBIFRecords
@test length(set3) == 20
# Version using ranged pairs
set3 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true, "decimalLatitude" => (0.0, 50.0))
@test typeof(set3) == GBIFRecords
@test length(set3) == 20

# Version with the full query - this one has about 250 records
serval = GBIF.taxon("Leptailurus serval", strict=true)
obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40))
while length(obs) < size(obs)
occurrences!(obs)
end
@test length(obs) == size(obs)

# Version with the full query AND a set page size - this one has about 250 records
obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40), "limit" => 45)
while length(obs) < size(obs)
occurrences!(obs)
end
@test length(obs) == size(obs)

end

2 comments on commit cdd2690

@tpoisot
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/30930

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" cdd26903869dca6605b4db823bc09c8cf68b6d53
git push origin v0.3.3

Please sign in to comment.