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

Spatial plus sign fix #249

Merged
merged 4 commits into from
Mar 17, 2023
Merged

Spatial plus sign fix #249

merged 4 commits into from
Mar 17, 2023

Conversation

btylerburton
Copy link
Contributor

Pull Request

Related to GSA/data.gov#3549

About

PR TASKS

  • The actual code changes.
  • Tests written and passed.
  • Any changes to docs?
  • Bumped version number in setup.py (also checked on PyPi).

@btylerburton btylerburton requested a review from a team March 16, 2023 21:29
@nickumia-reisys
Copy link
Contributor

How does removing the + make this work now? What about - signs?

@jbrown-xentity
Copy link
Contributor

How does removing the + make this work now? What about - signs?

We found that our code wasn't handling + signs correctly, although the - are required for negative lat/long values. The + is pretty atypical (and is definitely not a part of the geojson spec, which expects an actual JSON number type), but it's way easier for us to handle this use case than to try to get the data providers to change how they are providing the data...

Copy link
Contributor

@jbrown-xentity jbrown-xentity left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @btylerburton , one small change I think!

Comment on lines 462 to 464
# replace all instances of '+' as this creates bad JSON https://github.com/GSA/data.gov/issues/3549
old_spatial = old_spatial.replace('+', '')

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to try to leave old_spatial as is, as that is the value given to us by the provider. I would rather see this change down near line 480, as the start of the transformation we do in that specific use case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @jbrown-xentity (having more context on this now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had chained the fix into line 481 old_spatial.strip().split(',') but then I realized that old_spatial is getting loaded in at L467 too and that we need to transform it before that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is anyone clear where initial spatial is getting saved into old_spatial? If I can find that I can ensure the initial value gets saved unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Although I don't like what I'm about to suggest, but the replace function in python is a pass-by-value function, so there's technically no issue saving the result to a new variable. It creates more mess in the code, but I think that's what you need for it to load into json and then do the real work...

@nickumia-reisys
Copy link
Contributor

How does removing the + make this work now? What about - signs?

We found that our code wasn't handling + signs correctly, although the - are required for negative lat/long values. The + is pretty atypical (and is definitely not a part of the geojson spec, which expects an actual JSON number type), but it's way easier for us to handle this use case than to try to get the data providers to change how they are providing the data...

That makes sense. You're saying that whatever library couldn't convert the string "+23" to the number 23. Okay.. There weren't any other issues with format parsing? It seems like this fix is one that should be handled differently. I think the problem stems from there not being a spec about this. But it should be a validation error and if we want to allow it anyway, there should be a connection between the validation failing and it entering this logic. But that's definitely out of the scope of this effort...

@btylerburton btylerburton force-pushed the spatial-plus-sign-fix branch from 2a0b86d to 4c2cb24 Compare March 17, 2023 15:42
@btylerburton
Copy link
Contributor Author

@nickumia-reisys
Copy link
Contributor

For clarity, the internal variable in the translate_spatial function was never actually modifying the true "old_spatial" variable. The change of naming helps to highlight that, so overall, great reviewing, but there was no functionality at stake.

Copy link
Contributor

@nickumia-reisys nickumia-reisys left a comment

Choose a reason for hiding this comment

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

🚃

@btylerburton btylerburton merged commit 434e24d into main Mar 17, 2023
@btylerburton btylerburton deleted the spatial-plus-sign-fix branch March 17, 2023 17:01
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.

3 participants