matplotlib4j icon indicating copy to clipboard operation
matplotlib4j copied to clipboard

Fixes test for histBuilder with locale ES_es

Open vfrico opened this issue 6 years ago • 4 comments

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 avatar Oct 29 '19 23:10 vfrico

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.

sh0nk avatar Oct 30 '19 10:10 sh0nk

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<Double>.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()

vfrico avatar Oct 31 '19 08:10 vfrico

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);
    }

sh0nk avatar Nov 01 '19 13:11 sh0nk

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

vfrico avatar Nov 03 '19 18:11 vfrico