Skip to content

Commit 2c51b45

Browse files
Make itables work better:
- Fix columns_with_iterables - Add widgets for multi filtering
1 parent 18526dc commit 2c51b45

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

intake_esm/core.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def __init__(
126126
self.derivedcat = registry or default_registry
127127
self._entries = {}
128128
self._requested_variables = []
129+
self._columns_with_iterables = columns_with_iterables or []
129130
self.datasets = {}
130131
self._validate_derivedcat()
131132

@@ -218,12 +219,31 @@ def interactive(self) -> None:
218219
"""
219220
Use itables to display the catalog in an interactive table. Use polars
220221
for performance ideally. Fall back to pandas if not.
222+
223+
We have to explode columns with iterables, otherwise javascript stringifcation
224+
can cause ellipsis to be rendered directly into the interactive table,
225+
losing actual data and inserting junk.
221226
"""
222227
try:
223228
df = self.esmcat._frames.polars # type:ignore[union-attr]
229+
if self._columns_with_iterables:
230+
df = df.explode(self._columns_with_iterables)
224231
except AttributeError:
225232
df = self.esmcat.df
226-
return itables.show(df)
233+
if self._columns_with_iterables:
234+
df = df.explode(self._columns_with_iterables, ignore_index=True)
235+
236+
return itables.show(
237+
df,
238+
search={'regex': True, 'caseInsensitive': True},
239+
layout={'top1': 'searchPanes'},
240+
searchPanes={
241+
'layout': 'columns-3',
242+
'cascadePanes': True,
243+
'columns': [i for i, _ in enumerate(df.columns)],
244+
},
245+
maxBytes=0,
246+
)
227247

228248
def __len__(self) -> int:
229249
return len(self.keys())

0 commit comments

Comments
 (0)