Skip to content

ak.array for empty strings #4725

Closed

Description

@ajpotts

We should be able to use ak.array to create an empty string. However, right now it gives an error:

In [5]: s = ak.array([], dtype="str_")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 s = ak.array([], dtype="str_")

File ~/git/arkouda/arkouda/numpy/pdarraycreation.py:336, in array(a, dtype, copy, max_bits)
    326     rep_msg = generic_msg(
    327         cmd=f"arraySegString<{encoded_np.dtype.name}>",
    328         args={"size": encoded_np.size},
    329         payload=_array_memview(encoded_np),
    330         send_binary=True,
    331     )
    332     parts = cast(str, rep_msg).split("+", maxsplit=3)
    333     return (
    334         Strings.from_parts(parts[0], parts[1])
    335         if dtype is None
--> 336         else akcast(Strings.from_parts(parts[0], parts[1]), dtype)
    337     )
    339 # If not strings, then check that dtype is supported in arkouda
    340 if dtype == bigint or a.dtype.name not in DTypes:
    341     # 2 situations result in attempting to call `bigint_from_uint_arrays`
    342     # 1. user specified i.e. dtype=ak.bigint
    343     # 2. too big to fit into other numpy types (dtype = object)

File ~/anaconda3/envs/arkouda-dev/lib/python3.13/site-packages/typeguard/__init__.py:891, in typechecked.<locals>.wrapper(*args, **kwargs)
    889 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
    890 check_argument_types(memo)
--> 891 retval = func(*args, **kwargs)
    892 check_return_type(retval, memo)
    894 # If a generator is returned, wrap it if its yield/send/return types can be checked

File ~/git/arkouda/arkouda/numpy/numeric.py:225, in cast(pda, dt, errors)
    223     return Categorical(pda)  # type: ignore
    224 elif dt is Strings or akdtype(dt) == str_:
--> 225     return pda[:]
    226 else:
    227     dt = akdtype(dt)

File ~/git/arkouda/arkouda/numpy/strings.py:367, in Strings.__getitem__(self, key)
    365     (start, stop, stride) = key.indices(self.size)
    366     self.logger.debug(f"start: {start}; stop: {stop}; stride: {stride}")
--> 367     repMsg = generic_msg(
    368         cmd="segmentedIndex",
    369         args={
    370             "subcmd": "sliceIndex",
    371             "objType": self.objType,
    372             "obj": self.entry,
    373             "dtype": self.entry.dtype,
    374             "key": [start, stop, stride],
    375         },
    376     )
    377     return Strings.from_return_msg(repMsg)
    378 elif isinstance(key, pdarray):

File ~/git/arkouda/arkouda/client.py:995, in generic_msg(cmd, args, payload, send_binary, recv_binary)
    993     else:
    994         assert payload is None
--> 995         return type_cast(Channel, channel).send_string_message(
    996             cmd=cmd, args=msg_args, size=size, recv_binary=recv_binary
    997         )
    998 except KeyboardInterrupt as e:
    999     # if the user interrupts during command execution, the socket gets out
   1000     # of sync reset the socket before raising the interrupt exception
   1001     type_cast(Channel, channel).connect(timeout=0)

File ~/git/arkouda/arkouda/client.py:513, in ZmqChannel.send_string_message(self, cmd, recv_binary, args, size, request_id)
    511 # raise errors or warnings sent back from the server
    512 if return_message.msgType == MessageType.ERROR:
--> 513     raise RuntimeError(return_message.msg)
    514 elif return_message.msgType == MessageType.WARNING:
    515     warnings.warn(return_message.msg)

RuntimeError: index out of bounds

Activity

  1. self-assigned this
    on Jul 22, 2025
  2. added 6 commits that reference this issue on Jul 22, 2025
    58b0329
    6c80188
    c65c806
    cae9cc4
    5735b0b
    91b7edd
  3. added a commit that references this issue on Jul 25, 2025
    a99681c
  4. added a commit that references this issue on Aug 20, 2025
    e807c69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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