Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing throws error #257

Open
dhalpern opened this issue May 3, 2024 · 0 comments
Open

Printing throws error #257

dhalpern opened this issue May 3, 2024 · 0 comments

Comments

@dhalpern
Copy link

dhalpern commented May 3, 2024

Printing the initial array loaded using cmlreaders throws an error

The following reproducible example:

import cmlreaders as cml
exp = 'FR1'
ix = cml.CMLReader.get_data_index()
exp_ix = ix.query('experiment == @exp')
df_sess = exp_ix.iloc[0]
buf = 1500
rel_start = -500
rel_stop = 2100
event_type = 'WORD'
reader = cml.CMLReader(subject=df_sess['subject'], 
                           experiment=df_sess['experiment'], session=df_sess['session'],
                           localization=df_sess['localization'], montage=df_sess['montage'])
events = reader.load('task_events')
events = events.query('type == @event_type and eegoffset != -1')
events = events[events['list'] > 0]
if 'stim_params' in events.columns:
    events.drop(columns='stim_params', inplace=True)
if 'distractor' in events.columns:
    events.drop(columns='distractor', inplace=True)
scheme = reader.load("pairs")
dat = reader.load_eeg(events=events.iloc[0:12],
                    rel_start=-buf+rel_start,
                    rel_stop=buf+rel_stop,
                    scheme=scheme).to_ptsa()

Returns

TypeError                                 Traceback (most recent call last)
File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/IPython/core/formatters.py:344, in BaseFormatter.__call__(self, obj)
    342     method = get_real_method(obj, self.print_method)
    343     if method is not None:
--> 344         return method()
    345     return None
    346 else:

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/common.py:173, in AbstractArray._repr_html_(self)
    171 if OPTIONS["display_style"] == "text":
    172     return f"<pre>{escape(repr(self))}</pre>"
--> 173 return formatting_html.array_repr(self)

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/formatting_html.py:322, in array_repr(arr)
    320 if hasattr(arr, "xindexes"):
    321     indexes = _get_indexes_dict(arr.xindexes)
--> 322     sections.append(index_section(indexes))
    324 sections.append(attr_section(arr.attrs))
    326 return _obj_repr(arr, header_components, sections)

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/formatting_html.py:199, in _mapping_section(mapping, name, details_func, max_items_collapse, expand_option_name, enabled)
    192 expanded = _get_boolean_with_default(
    193     expand_option_name, n_items < max_items_collapse
    194 )
    195 collapsed = not expanded
    197 return collapsible_section(
    198     name,
--> 199     details=details_func(mapping),
    200     n_items=n_items,
    201     enabled=enabled,
    202     collapsed=collapsed,
    203 )

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/formatting_html.py:159, in summarize_indexes(indexes)
    158 def summarize_indexes(indexes):
--> 159     indexes_li = "".join(
    160         f"<li class='xr-var-item'>{summarize_index(v, i)}</li>"
    161         for v, i in indexes.items()
    162     )
    163     return f"<ul class='xr-var-list'>{indexes_li}</ul>"

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/formatting_html.py:160, in <genexpr>(.0)
    158 def summarize_indexes(indexes):
    159     indexes_li = "".join(
--> 160         f"<li class='xr-var-item'>{summarize_index(v, i)}</li>"
    161         for v, i in indexes.items()
    162     )
    163     return f"<ul class='xr-var-list'>{indexes_li}</ul>"

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/formatting_html.py:144, in summarize_index(coord_names, index)
    142 index_id = f"index-{uuid.uuid4()}"
    143 preview = escape(inline_index_repr(index))
--> 144 details = short_index_repr_html(index)
    146 data_icon = _icon("icon-database")
    148 return (
    149     f"<div class='xr-index-name'><div>{name}</div></div>"
    150     f"<div class='xr-index-preview'>{preview}</div>"
   (...)
    154     f"<div class='xr-index-data'>{details}</div>"
    155 )

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/formatting_html.py:136, in short_index_repr_html(index)
    133 if hasattr(index, "_repr_html_"):
    134     return index._repr_html_()
--> 136 return f"<pre>{escape(repr(index))}</pre>"

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/xarray/core/indexes.py:568, in PandasIndex.__repr__(self)
    567 def __repr__(self):
--> 568     return f"PandasIndex({repr(self.index)})"

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/pandas/core/indexes/base.py:1233, in Index.__repr__(self)
   1229 """
   1230 Return a string representation for this object.
   1231 """
   1232 klass_name = type(self).__name__
-> 1233 data = self._format_data()
   1234 attrs = self._format_attrs()
   1235 space = self._format_space()

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/pandas/core/indexes/base.py:1275, in Index._format_data(self, name)
   1272     if is_object_dtype(self.categories):
   1273         is_justify = False
-> 1275 return format_object_summary(
   1276     self,
   1277     self._formatter_func,
   1278     is_justify=is_justify,
   1279     name=name,
   1280     line_break_each_value=self._is_multi,
   1281 )

File /usr/global/miniconda/py310_23.1.0-1/envs/workshop_311/lib/python3.11/site-packages/pandas/io/formats/printing.py:436, in format_object_summary(obj, formatter, is_justify, name, indent_for_name, line_break_each_value)
    433     line = space2
    435 for tail_item in tail[:-1]:
--> 436     word = tail_item + sep + " "
    437     summary, line = _extend_line(summary, line, word, display_width, space2)
    439 # last value: no sep added + 1 space of width used for trailing ','

TypeError: can only concatenate tuple (not "str") to tuple
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

No branches or pull requests

1 participant