Skip to content

ak.ArrayBuilder.show passes Formatter to ak.Array.show, causing TypeError #3724

@T90REAL

Description

@T90REAL

Version of Awkward Array

2.8.10

Description and code to reproduce

The ak.ArrayBuilder.show docs state that the method “takes a snapshot of the data and calls show on it, so the arguments should be forwarded unchanged. The ak.Array.show docs specify that formatter must be a mapping or None. In the current implementation, ArrayBuilder.show wraps the caller’s formatter into a Formatter object before delegating to snapshot().show, so Array.show receives a Formatter instance and attempts to subscript it, triggering TypeError.

import awkward as ak

builder = ak.ArrayBuilder()
builder.begin_list()
builder.real(1.2)
builder.end_list()

builder.show(stream=None)
Traceback (most recent call last):
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 291, in __call__
    impl = self._cache[type(obj)]
           ~~~~~~~~~~~^^^^^^^^^^^
KeyError: <class 'numpy.float64'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/src/test.py", line 8, in <module>
    builder.show(stream=None)
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/highlevel.py", line 2878, in show
    return self.snapshot().show(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/highlevel.py", line 1441, in show
    rows = highlevel_array_show_rows(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 482, in highlevel_array_show_rows
    array_line = valuestr(array, limit_rows, limit_cols, formatter=formatter_impl)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 378, in valuestr
    _, strs = valuestr_horiz(get_at(data, index), limit_cols - 2, formatter)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 166, in valuestr_horiz
    cols_taken, strs = valuestr_horiz(get_at(data, 0), limit_cols, formatter)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 279, in valuestr_horiz
    out = formatter(data)
          ^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 293, in __call__
    impl = self._find_formatter_impl(type(obj))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/prettyprint.py", line 316, in _find_formatter_impl
    return self._formatters["float"]
           ~~~~~~~~~~~~~~~~^^^^^^^^^
TypeError: 'Formatter' object is not subscriptable

builder.show(stream=None) should succeed and match builder.snapshot().show(stream=None).

Note: This issue was identified by an automated testing tool for academic research and manually verified. If you have any concerns about this type of reporting, please let me know, and I will adjust my workflow accordingly.

Metadata

Metadata

Assignees

Labels

bugThe problem described is something that must be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions