Repository navigation
Description
the way we handle determining the type of a scalar is a bit funky and we handle it differently in different places. This was discovered in #2447.
taking a look at this example, we see that 2**63 + 1 is being interpreted as an int i.e. -9223372036854775807 when it should be a uint.
In [3]: ak.dtypes.resolve_scalar_dtype(2**63 + 1)
Out[3]: 'int64'
In [4]: ak.arange(10) + (2**63 + 1)
Out[4]: array([-9223372036854775807 -9223372036854775806 -9223372036854775805 -9223372036854775804 -9223372036854775803 -9223372036854775802 -9223372036854775801 -9223372036854775800 -9223372036854775799 -9223372036854775798])
In [5]: ak.dtypes.resolve_scalar_dtype(2**65)
Out[5]: 'int64'
In [6]: ak.arange(10) + 2**65
Out[6]: array(["36893488147419103232" "36893488147419103233" "36893488147419103234" "36893488147419103235" "36893488147419103236" "36893488147419103237" "36893488147419103238" "36893488147419103239" "36893488147419103240" "36893488147419103241"])resolve_scalar_dtype also sees 2**65 as a int instead of a bigint
we handle this differently in different spots:
Lines 261 to 266 in 3bf0ea9
| # Python int or np.int* or np.uint* | |
| elif isinstance(val, int) or (hasattr(val, "dtype") and cast(np.uint, val).dtype.kind in "ui"): | |
| if isinstance(val, np.uint64): | |
| return "uint64" | |
| else: | |
| return "int64" |
Lines 214 to 215 in 3bf0ea9
| if isinstance(val, int) and val >= 2**64: | |
| return ParameterObject(key, ObjectType.VALUE, bigint.name, v) |
arkouda/arkouda/pdarrayclass.py
Lines 360 to 369 in 3bf0ea9
| dt = resolve_scalar_dtype(other) | |
| if self.dtype != bigint and np.can_cast(other, self.dtype): | |
| # If scalar can be losslessly cast to array dtype, | |
| # do the cast so that return array will have same dtype | |
| dt = self.dtype.name | |
| other = self.dtype.type(other) | |
| else: | |
| # see if other is a bigint | |
| if isSupportedInt(other) and other >= 2**64: | |
| dt = bigint.name |
I think we should add these checks for if >=2**63 then uint and if >=2**64 then bigint to resolve_scalar_dtype and then update all these sites to use that instead
Activity
stress-tess commentedon Jun 15, 2023
we should def aim for this to behave like numpy with
realreturnsCloses Bears-R-Us#2505: Update resolve_scalar_dtype to handled uint a…
Closes #2505: Update resolve_scalar_dtype to handled uint and bigint (#…