Repository navigation
array[:] = value silently coerce value to array type even when unsafe #1164
Copy link
Copy link
Closed
Description
Activity
Silent string to int conversion happens too, which makes me really sad 😢 :
>>> source = np.array(["1", "2"]) >>> target[:] = source >>> target [1 2]
I just realized this problem is not specific to CheckedSession:
>>> target = zeros(a, dtype=int) >>> source = ndtest(a) * 1.6 >>> source a a0 a1 0.0 1.6 >>> target[:] = source >>> target a a0 a1 0 1 >>> source = Array(["1", "2"], a) >>> source a a0 a1 1 2 >>> target[:] = source >>> target a a0 a1 1 2
The only thing specific to CheckedSession is that it is even more confusing because
cs.v = arractually doescs.v[:] = arrcs.v = arr.astype(int)behind the scene :>>> cs.v = arr >>> cs.v a a0 a1 0 1
- changed the title
[-]CheckedSession silently coerce to declared dtype even when unsafe[/-][+]array[:] = value silently coerce value to array type even when unsafe[/+]on Feb 25, 2026 Even though the problem lies with numpy, I think that LArray as the more-user-friendly-less-performance project should tackle this issue directly without waiting for numpy to fix it
Given how CheckedSession are implemented (contrary to what I thought,
cs.v = arrdoes NOT docs.v[:] = arrbut rathercs.v = arr.astype(declared_dtype), I think the issue needs to be fixed explicitly for CheckedSession in addition to the general fix.- added 2 commits that reference this issue
on Mar 27, 2026 - added a commit that references this issue
on Apr 3, 2026 - added a commit that references this issue
on Apr 14, 2026
Unsure if this should be a warning or an error, but doing this silently is clearly not acceptable to me for unsafe conversions.
Surprisingly Numpy has the issue too (I suppose we inherit it from there):
This has been a known issue in Numpy for a looong time but even though the developers seem to agree it is unfortunate, it will be a while until that behavior can be changed (if ever) in Numpy. See numpy/numpy#7730 and numpy/numpy#8733