Skip to content

Conversation

@LeeDongGeon1996
Copy link
Collaborator

@LeeDongGeon1996 LeeDongGeon1996 commented Jun 4, 2024

Description

  • Apply CultureInfo.InvariantCulture not to be affected by system locale setting

Fixes:

Checklist

  • My code follows the existing style, code structure, and naming taxonomy
  • I have commented my code, particularly in hard-to-understand areas
  • I have performed a self-review of my own code and included any verifying manual calculations
  • I have added or updated unit tests that prove my fix is effective or that my feature works, and achieves sufficient code coverage. New and existing unit tests pass locally and in the build (below) with my changes
  • My changes generate no new warnings and running code analysis does not produce any issues
  • I have added or run the performance tests that depict optimal execution times
  • I have made corresponding changes to the documentation

@LeeDongGeon1996 LeeDongGeon1996 changed the title Fix: Apply CultureInfo.InvariantCulture not to be affected by locale setting fix: Apply CultureInfo.InvariantCulture not to be affected by locale setting Jun 4, 2024
@LeeDongGeon1996 LeeDongGeon1996 changed the title fix: Apply CultureInfo.InvariantCulture not to be affected by locale setting fix: Apply CultureInfo.InvariantCulture not to be affected by system locale setting Jun 4, 2024
@LeeDongGeon1996 LeeDongGeon1996 marked this pull request as ready for review August 4, 2024 09:23
Copy link
Member

@DaveSkender DaveSkender left a comment

Choose a reason for hiding this comment

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

LGTM, but check the Codacy findings to fix, or ignore any false-positives.

@LeeDongGeon1996
Copy link
Collaborator Author

LGTM, but check the Codacy findings to fix, or ignore any false-positives.

@DaveSkender Yeap. All of those can be ignored

@LeeDongGeon1996
Copy link
Collaborator Author

@DaveSkender Just a trivial thing. Which version should be increased? minor or patch?
The thing is that the code change is not that much, but the impact may be big

@DaveSkender
Copy link
Member

DaveSkender commented Aug 6, 2024

@DaveSkender Just a trivial thing. Which version should be increased? minor or patch? The thing is that the code change is not that much, but the impact may be big

If there’s no change to the actual API and is not a breaking change, patch is all you’d need. If you consider this a new feature, minor. Just a patch IMO, even if a big relief to users.

@DaveSkender
Copy link
Member

I don't have any open concerns with this, LGTM. Please proceed with it.

@LeeDongGeon1996
Copy link
Collaborator Author

LeeDongGeon1996 commented Aug 11, 2024

@DaveSkender An idea came up with!
The problem is we need to convert C# Decimal into Python Decimal, Culture-Invariantly.
And C# double is automatically converted into Python float and this does not affected by locale setting.
Maybe we can use this (if we take precision loss a bit):

  1. Convert C# decimal into C# double first
  2. And then, it's converted into Python float by pythonnet.

def test_auto_conversion_from_double_to_float(self):
from System import Double as CsDouble
cs_double = CsDouble.Parse('1996.1012', CsCultureInfo.InvariantCulture)
assert isinstance(cs_double, Number)
assert isinstance(cs_double, float)
assert 1996.1012 == cs_double

@LeeDongGeon1996 LeeDongGeon1996 merged commit 283c83f into facioquo:main Aug 11, 2024
@LeeDongGeon1996 LeeDongGeon1996 deleted the fix/apply-locale branch August 11, 2024 11:52
@LeeDongGeon1996
Copy link
Collaborator Author

LeeDongGeon1996 commented Aug 11, 2024

@DaveSkender I had a quick test. And this way has max 3x performance gain!

    if cs_decimal is not None:
        return CsDecimal.ToDouble(cs_decimal)

But few tests fails due to precision problem

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

decimal.InvalidOperation with small numbers System.FormatException: Input string was not in a correct format

2 participants