FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Converting numpy float64 of python float to Decimal is not the same (get rounded in numpy case) · Issue #1833 · pythonnet/pythonnet · GitHub

Repository navigation

Converting numpy float64 of python float to Decimal is not the same (get rounded in numpy case) #1833

Closed

Description

Environment

  • Pythonnet version: '2.5.1'
  • Python version: 3.8.12
  • Operating System: Win10
  • .NET Runtime: 4.8.4470.0
  • numpy version: 1.21.4

Details

  • Describe what you were trying to get done.

I had to convert floats to Decimal but somehow the current Double I got out of Decimal when looking at it using ToDouble would give me only the round part of the double. I figured that my floats were not native python but numpy float64 . This issue happens only with numpy floats..

    import clr
    from System import Decimal
    import numpy as np

    d= 45.5
    assert d == np.array([d])[0]  # should be fine
    assert Decimal(d) == Decimal(np.array([d])[0])  # assertion error 
    

Activity

  1. changed the title [-]Converting numpy float64 of python float to Decimal is rounding it[/-] [+]Converting numpy float64 of python float to Decimal is not the same (get rounded in numpy case)[/+] on Jun 24, 2022
  2. lostmsu commented on Jun 24, 2022

    Member

    Python.NET 2.x permits all sorts of conversions in attempts to match the function arguments, some of which permit data loss. Please, try 3.0 previews of Python.NET. I believe 3.0 will tell you your Decimal(np.float64) call has no matching constructor overloads forcing you to explicitly convert np.float64 to either Python float or to System.Double first.

    Also, to save time please add info about investigation from your side. E.g. in the example the equality of two decimals fails. What are their values at the time of comparison? Surely you checked before opening the bug.

  3. filmor commented on Sep 20, 2022

    Member

    This is fixed in rc6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL