Skip to content

Fix Map() repr to be more sane#2997

Merged
maxnoe merged 3 commits into
mainfrom
fix/map_repr
May 8, 2026
Merged

Fix Map() repr to be more sane#2997
maxnoe merged 3 commits into
mainfrom
fix/map_repr

Conversation

@kosack
Copy link
Copy Markdown
Member

@kosack kosack commented Apr 20, 2026

The old repr was basically unreadable, as it printed the reprs of all sub-containers. This just changes the repr to be actually useful:

event.dl1.tel

After this change:

Map[int, ctapipe.containers.ArrayEventContainer](keys=[13, 6])

Before: Too much information was given. The Container reprs are only useful when dealing with a single one, not a list. What the user wants when looking at a Map is just the list of what is inside it.

Map(ctapipe.containers.DL1CameraContainer, {np.int16(5): ctapipe.containers.DL1CameraContainer:
                         image: Numpy array of camera image, after waveform
                                extraction.Shape: (n_pixel) if n_channels is 1
                                or data is gain selectedelse: (n_channels,
                                n_pixel) with default None
                     peak_time: Numpy array containing position of the peak of
                                the pulse as determined by the extractor.Shape:
                                (n_pixel) if n_channels is 1 or data is gain
                                selectedelse: (n_channels, n_pixel) with default
                                None
                    image_mask: Boolean numpy array where True means the pixel
                                has passed cleaning. Shape: (n_pixel, ) with
                                default None as a 1-D array with dtype bool
                      is_valid: True if image extraction succeeded, False if
                                failed or in the case of TwoPass methods, that
                                the first pass only was returned. with default
                                False
                  parameters.*: Image parameters with default None with type
                                <class
                                'ctapipe.containers.ImageParametersContainer'>, np.int16(11): ctapipe.containers.DL1CameraContainer:
                         image: Numpy array of camera image, after waveform
                                extraction.Shape: (n_pixel) if n_channels is 1
                                or data is gain selectedelse: (n_channels,
                                n_pixel) with default None
                     peak_time: Numpy array containing position of the peak of
                                the pulse as determined by the extractor.Shape:
                                (n_pixel) if n_channels is 1 or data is gain
                                selectedelse: (n_channels, n_pixel) with default
                                None
                    image_mask: Boolean numpy array where True means the pixel
                                has passed cleaning. Shape: (n_pixel, ) with
                                default None as a 1-D array with dtype bool
                      is_valid: True if image extraction succeeded, False if
                                failed or in the case of TwoPass methods, that
                                the first pass only was returned. with default
                                False
                  parameters.*: Image parameters with default None with type
                                <class
                                'ctapipe.containers.ImageParametersContainer'>})

kosack added 2 commits April 20, 2026 17:45
The old repr was basically unreadable, as it printed the reprs of all
sub-containers.  This just changes the repr to be actually useful:

```python
event.dl1.tel
```
After:
```
Map(ctapipe.containers.DL1CameraContainer: [np.int16(5), np.int16(11)])
```
@maxnoe
Copy link
Copy Markdown
Member

maxnoe commented Apr 20, 2026

Map(ctapipe.containers.DL1CameraContainer: [np.int16(5), np.int16(11)])

I find it a bit weird to see value_type: keys. Usually maps are the other way around.

Maybe something like: Map[key_type, value_type](keys={keys}) would be more intuitive?

@ctao-sonarqube
Copy link
Copy Markdown

@maxnoe maxnoe requested a review from mexanick May 8, 2026 09:05
Copy link
Copy Markdown
Contributor

@mexanick mexanick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually found the previous verbose repr useful :D But I see the point in making it concise.

@maxnoe
Copy link
Copy Markdown
Member

maxnoe commented May 8, 2026

I actually found the previous verbose repr useful :D But I see the point in making it concise.

It woudl repeat the same container repr for every entry in the map... that's hardly useful.

I proposed to change the container repr to show the data content and not the help, but @kosack opposed this. I still think a data containers repr should show its content and not its docstring.

@maxnoe maxnoe merged commit 5561e92 into main May 8, 2026
12 checks passed
@maxnoe maxnoe deleted the fix/map_repr branch May 8, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants