Skip to content

fix regression in lib/clean_number (alternate) #1185

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 2 commits into from
Nov 22, 2016

Conversation

etpinard
Copy link
Contributor

fixes #1183

An alternate take on #1184

- allow , and spaces in middle of numeric strings
@etpinard etpinard added status: reviewable bug something broken labels Nov 21, 2016
[' \'\n \r -9.2e7 \t\' ', -9.2e7]
[' \'\n \r -9.2e7 \t\' ', -9.2e7],
['1,690,000', 1690000],
['1 690 000', 1690000],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so maybe we should also include ' and - (or is that a \cdot)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd vote to not do any more replacements than we did previously, we'll start to hit other issues if we try to accept other separators like that automatically in every number string we see. We can build tools into the workspace that help people with these situations but lets keep them out of plotly.js

[' \'\n \r -9.2e7 \t\' ', -9.2e7],
['1,690,000', 1690000],
['1 690 000', 1690000],
['2 2', 22],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh good call - '1 690 000' will show up. '2 2' looks weird, and likely to be a parsing error, but I don't see how we can distinguish it from legitimate spaces in numbers.

v = v
.replace(FRONTJUNK, '')
.replace(ENDJUNK, '')
.replace(GLOBALJUNK, '');
Copy link
Collaborator

Choose a reason for hiding this comment

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

The perf tests I did when playing with dates make me think it'll be faster to turn this into a single regex, but we should test that intuition, since this is a very hot path.

Also do we really want to allow any and all internal whitespace? Including line breaks and tabs? Or can we do just regular spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The perf tests I did when playing with dates make me think it'll be faster to turn this into a single regex

Good call. I'll update this.

Also do we really want to allow any and all internal whitespace?

Just ' ' is probably enough. It is also what we used to do here:

https://github.com/plotly/plotly.js/pull/1078/files#diff-9664b6a57e7771275ffd0c8805ea5917L30

- and allow only ' ' in middle instead of all space characters
@etpinard etpinard force-pushed the clean-datum-regression-alt branch from f804b64 to 79fe7d5 Compare November 21, 2016 23:15
['1 690 000', 1690000],
['2 2', 22],
['$5,162,000.00', 5162000],
[' $1,410,000.00 ', 1410000],
Copy link
Member

@chriddyp chriddyp Nov 21, 2016

Choose a reason for hiding this comment

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

another one: " - " to whatever it was before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here's the old replace call

c = c.toString().replace(/['"%,$# ]/g, '');

we didn't do anything to -

@alexcjohnson
Copy link
Collaborator

I'd say 💃 to this one, and close #1184

@etpinard etpinard merged commit 846f2c7 into master Nov 22, 2016
@etpinard etpinard deleted the clean-datum-regression-alt branch November 22, 2016 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

certain data input strings lead to broken plots.
3 participants