Skip to content

parse all numbers as Float64 when reading JSON #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

Merged
merged 1 commit into from
Nov 14, 2022
Merged

parse all numbers as Float64 when reading JSON #54

merged 1 commit into from
Nov 14, 2022

Conversation

visr
Copy link
Member

@visr visr commented Nov 13, 2022

This will avoid problems with coordinates like 1 or 1.0 being converted to Int. This also affects the properties, so integer columns will now be Float64, and will need to be manually converted to integer types.

This is now possible in the latest JSON3 release with PR quinnj/JSON3.jl#240.
Fixes #52, also cc @jeremiahpslewis who ran into issues with this for GeoMakie.

Due to the effect on properties this should probably be released as a breaking change.

This will avoid problems with coordinates like 1 or 1.0 being converted to Int. This also affects the properties, so integer columns will now be Float64, and will need to be manually converted to integer types.
@visr visr requested a review from rafaqz November 13, 2022 20:00
@@ -17,7 +17,7 @@ Extents = "0.1"
GeoFormatTypes = "0.4"
GeoInterface = "1"
GeoInterfaceRecipes = "1"
JSON3 = "1"
JSON3 = "1.12"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be 1.1? Note that real breaks need v2. But, I'm not sure if this is really breaking, it seems more like fixing a bug to me.

(And I generally find it better not to bump versions in PRs)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the JSON3 version, not GeoJSON. I didn't bump the GeoJSON version yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

About breaking/not breaking, I agree for coordinates it's definitely bugfix. For integer properties it could be a minor change, I'm also fine with releasing as non-breaking.

Copy link
Member

Choose a reason for hiding this comment

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

Lol I never read toml files correctly in PRs. But yes, bugfix it is.

@@ -5,7 +5,7 @@
Read a GeoJSON string to a GeoInterface.jl compatible feature or geometry object.
"""
function read(source)
object = JSON3.read(source)
object = JSON3.read(source; numbertype = Float64)
Copy link
Member

Choose a reason for hiding this comment

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

Should we allow passing the numbertype keyword through read?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think not using this setting is a real footgun, not sure we should offer that option. I doubt it's ever useful in practice.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, makes sense. I just saw the tests had used Int previously and wondered if we should facilitate numvertype=Int in case anyone else was using Int. But I guess that's not really a real scenario.

@visr visr merged commit 123e2bf into main Nov 14, 2022
@visr visr deleted the numbertype branch November 14, 2022 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Geometry coordinates aren't parsed as the same type
2 participants