This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Strange behavior with sparse.dok_matrix decimal is cast to integer
Type: behavior Stage:
Components: Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: browser.365, eric.smith
Priority: normal Keywords:

Created on 2020-08-19 17:18 by browser.365, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg375660 - (view) Author: browser.365 (browser.365) Date: 2020-08-19 17:18
import numpy as np
from scipy import sparse
import decimal
D = decimal.Decimal

Al = sparse.dok_matrix((10, 10), dtype=np.dtype(D))
Al.astype(D)

Al[1,1] = D('0.1')
print(Al[1,1])
print(type(Al[1,1]))

Al[0,0] = D('0')
print(Al[0,0])
print(type(Al[0,0]))



z = decimal.Decimal('0')

print(z)
print(type(z))
print(' - ')


Running the above code gives:

0.1
<class 'decimal.Decimal'>
0
<class 'int'>
0
<class 'decimal.Decimal'>
 - 

All of the elements should be decimal.
msg375664 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-08-19 17:34
This seems like a scipy or numpy issue, not a Python bug. You might have better luck asking about this behavior on a scipy or numpy forum of some kind, or maybe on Stackoverflow.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85755
2020-08-19 17:34:31eric.smithsetnosy: + eric.smith
messages: + msg375664
2020-08-19 17:18:37browser.365create