Skip to content

Fixes test for histBuilder with locale ES_es #8

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vfrico
Copy link

@vfrico vfrico commented Oct 29, 2019

commit:13a3fd2 When using locale ES_es, double formatting uses a comma instead
a decimal dot. So, an specific conversion has to be done

vfrico and others added 3 commits October 23, 2019 11:06
When using locale ES_es, double formatting uses a comma instead
a decimal dot. So, an specific conversion has to be done
@sh0nk
Copy link
Owner

sh0nk commented Oct 30, 2019

Good catch! What happens for methods with a single double arg and list args? e.g. hist.bottom(1.2) or plt.plot().add(Arrays.asList(1.3, 2)). Could you add test cases with ES_es locale for them and also your original fix?

If they are also impacted, they'd be fixed at once. In such case, prefer calling TypeConversion.INSTANCE.toSafeDouble on more abstract layer such as CompositeBuilder#addToArgs and CompositeBuilder#addToKwargs.

@@ -17,4 +18,8 @@
}
}).collect(Collectors.toList());
}

public String toSafeDouble(Double d) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can this arg be changed to unboxed double, since if null is passed accidentally, that is stringified as null which is invalid for python?

Copy link
Author

Choose a reason for hiding this comment

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

I've just added a commit.

@vfrico
Copy link
Author

vfrico commented Oct 31, 2019

Good catch! What happens for methods with a single double arg and list args? e.g. hist.bottom(1.2) or plt.plot().add(Arrays.asList(1.3, 2)). Could you add test cases with ES_es locale for them and also your original fix?

If they are also impacted, they'd be fixed at once. In such case, prefer calling TypeConversion.INSTANCE.toSafeDouble on more abstract layer such as CompositeBuilder#addToArgs and CompositeBuilder#addToKwargs.

The problem seems to arise only when using String.format() with a double. When doing an List.toString() or double[].toString(), Java does it correctly

> $ jshell                                                                                              
|  Welcome to JShell -- Version 11.0.4
|  For an introduction type: /help intro

jshell> Locale currentLocale = Locale.getDefault();
currentLocale ==> es_ES

jshell> System.out.println(List.of(5.6, 7.8));
[5.6, 7.8]

jshell> System.out.println(Arrays.toString(new double[] {5.6, 7.8}));
[5.6, 7.8]

jshell> System.out.println("Double value is "+ 8.9);
Double value is 8.9

jshell> System.out.println(String.format("Double value is %.2f", 8.9));
Double value is 8,90

So I don't think it is necessary to do it in all string conversions, but only on those that use String.format()

@sh0nk
Copy link
Owner

sh0nk commented Nov 1, 2019

So I don't think it is necessary to do it in all string conversions, but only on those that use String.format()

This is very interesting. I would like to avoid any other future change missing to call toSafeDouble. Then, what about adding the default locale ROOT which does not depend on the locale setting globally in matplotlib4j instead of having toSafeDouble?

    PlotImpl(PythonConfig pythonConfig, boolean dryRun) {
        this.pythonConfig = pythonConfig;
        this.dryRun = dryRun;

        Locale.setDefault(Locale.ROOT);
    }

@vfrico
Copy link
Author

vfrico commented Nov 3, 2019

Yeah, of course!
It is another option. I suppose it will work.
I'll try it to see if we get the desired output

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.

2 participants