Skip to content

Commit 3e19f50

Browse files
committed
Enhance DataSet representation: add detailed __repr__ method and include attribute names in HTML output for improved usability in interactive sessions
1 parent cb68cb0 commit 3e19f50

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

doc/release_notes/release_3.14.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
* New `_repr_html_()` method on `LabeledEnum` class for formatted display of enum values with labels
1010
* CSS styling with `.guidata-dataset-table` class for consistent visual appearance
1111
* Automatically called by Jupyter when displaying objects as cell output
12+
* HTML representation now includes attribute names in a third column for easier programmatic access
13+
14+
* **Interactive Python experience**: Improved DataSet representation in Python interpreters
15+
* New `__repr__()` method on `DataSet` class shows attribute names instead of labels
16+
* Makes it easy to discover attribute names when working interactively in a Python shell or notebook
17+
* `print(dataset)` still shows user-friendly labels, while `repr(dataset)` or just typing the variable shows attribute names
1218

1319
* **Secure build utility**: Added `--prebuild` option to run commands before package build
1420
* New `--prebuild` command-line argument for `guidata.utils.securebuild`

guidata/dataset/datatypes.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,14 @@ def __str__(self) -> str:
16061606
"""Return string representation of the data set"""
16071607
return self.to_string(debug=False)
16081608

1609+
def __repr__(self) -> str:
1610+
"""Return detailed representation showing attribute names.
1611+
1612+
This is useful in interactive Python sessions to discover
1613+
the attribute names needed to access/modify dataset items.
1614+
"""
1615+
return self.to_string(debug=True)
1616+
16091617
def check(self) -> list[str]:
16101618
"""Check the dataset item values
16111619
@@ -1858,12 +1866,19 @@ def to_html(self) -> str:
18581866
# Get string representation of value
18591867
value_str = item.get_string_value(self)
18601868

1869+
# Get attribute name for programmatic access
1870+
attr_name = item._name
1871+
18611872
html += (
18621873
f'<tr><td style="text-align: right; vertical-align: top;">{label}:</td>'
18631874
)
18641875
html += (
1865-
f'<td style="text-align: left; padding-left: 10px;">'
1866-
f"{value_str}</td></tr>"
1876+
f'<td style="text-align: left; padding-left: 10px;">{value_str}</td>'
1877+
)
1878+
html += (
1879+
f'<td style="text-align: left; padding-left: 15px; '
1880+
f'color: #888; font-family: monospace; font-size: 0.9em;">'
1881+
f"({attr_name})</td></tr>"
18671882
)
18681883

18691884
html += "</table>"

0 commit comments

Comments
 (0)