Skip to content

weirdness with resolve_scalar_dtype #2505

Closed

Description

@stress-tess

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:

arkouda/arkouda/dtypes.py

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"

arkouda/arkouda/message.py

Lines 214 to 215 in 3bf0ea9

if isinstance(val, int) and val >= 2**64:
return ParameterObject(key, ObjectType.VALUE, bigint.name, v)

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

  1. self-assigned this
    on Jun 14, 2023
  2. added
    Technical Debt
    bug
    on Jun 14, 2023
  3. stress-tess commented on Jun 15, 2023

    @stress-tess
    MemberAuthor

    we should def aim for this to behave like numpy with real returns

    In [6]: np.arange(10) + (2**63 + 1)
    Out[6]:
    array([9.22337204e+18, 9.22337204e+18, 9.22337204e+18, 9.22337204e+18,
           9.22337204e+18, 9.22337204e+18, 9.22337204e+18, 9.22337204e+18,
           9.22337204e+18, 9.22337204e+18])
  4. added a commit that references this issue on Jun 28, 2023
    6524f41
  5. added a commit that references this issue on Jun 29, 2023
    7282f0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Technical Debtbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions