Skip to content

Commit cf77fd2

Browse files
jaychiaJay Chia
andauthored
[CHORE] Left-align headers in reprs (#1880)
Co-authored-by: Jay Chia <jaychia94@gmail.com@users.noreply.github.com>
1 parent 195174c commit cf77fd2

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/daft-core/src/schema.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ impl Schema {
124124
res.push_str("<thead><tr>");
125125

126126
for (name, field) in &self.fields {
127-
res.push_str("<th style=\"text-wrap: nowrap; max-width:192px; overflow:auto\">");
127+
res.push_str(
128+
"<th style=\"text-wrap: nowrap; max-width:192px; overflow:auto; text-align:left\">",
129+
);
128130
res.push_str(&html_escape::encode_text(name));
129131
res.push_str("<br />");
130132
res.push_str(&html_escape::encode_text(&format!("{}", field.dtype)));

src/daft-table/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ impl Table {
457457
res.push_str("<thead><tr>");
458458

459459
for (name, field) in &self.schema.fields {
460-
res.push_str("<th style=\"text-wrap: nowrap; max-width:192px; overflow:auto\">");
460+
res.push_str(
461+
"<th style=\"text-wrap: nowrap; max-width:192px; overflow:auto; text-align:left\">",
462+
);
461463
res.push_str(&html_escape::encode_text(name));
462464
res.push_str("<br />");
463465
res.push_str(&html_escape::encode_text(&format!("{}", field.dtype)));

tests/dataframe/test_repr.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
UNMATERIALIZED_REGEX = re.compile(r".*\(No data to display: Dataframe not materialized\).*")
1515
MATERIALIZED_NO_ROWS_REGEX = re.compile(r".*\(No data to display: Materialized dataframe has no rows\).*")
1616
TD_STYLE = 'style="text-align:left; max-width:192px; max-height:64px; overflow:auto"'
17+
TH_STYLE = 'style="text-wrap: nowrap; max-width:192px; overflow:auto; text-align:left"'
1718

1819

1920
def parse_str_table(
@@ -93,9 +94,9 @@ def test_empty_df_repr(make_df):
9394
assert parse_str_table(df.__repr__(), expected_user_msg_regex=UNMATERIALIZED_REGEX) == expected_data
9495
assert (
9596
df._repr_html_()
96-
== """<div>
97+
== f"""<div>
9798
<table class="dataframe">
98-
<thead><tr><th style="text-wrap: nowrap; max-width:192px; overflow:auto">A<br />Int64</th><th style="text-wrap: nowrap; max-width:192px; overflow:auto">B<br />Utf8</th></tr></thead>
99+
<thead><tr><th {TH_STYLE}>A<br />Int64</th><th {TH_STYLE}>B<br />Utf8</th></tr></thead>
99100
</table>
100101
<small>(No data to display: Dataframe not materialized)</small>
101102
</div>"""
@@ -115,9 +116,9 @@ def test_empty_df_repr(make_df):
115116
assert parse_str_table(df.__repr__(), expected_user_msg_regex=MATERIALIZED_NO_ROWS_REGEX) == expected_data
116117
assert (
117118
df._repr_html_()
118-
== """<div>
119+
== f"""<div>
119120
<table class="dataframe">
120-
<thead><tr><th style="text-wrap: nowrap; max-width:192px; overflow:auto">A<br />Int64</th><th style="text-wrap: nowrap; max-width:192px; overflow:auto">B<br />Utf8</th></tr></thead>
121+
<thead><tr><th {TH_STYLE}>A<br />Int64</th><th {TH_STYLE}>B<br />Utf8</th></tr></thead>
121122
<tbody>
122123
</tbody>
123124
</table>
@@ -134,9 +135,9 @@ def test_alias_repr(make_df):
134135
assert parse_str_table(df.__repr__(), expected_user_msg_regex=UNMATERIALIZED_REGEX) == expected_data
135136
assert (
136137
df._repr_html_()
137-
== """<div>
138+
== f"""<div>
138139
<table class="dataframe">
139-
<thead><tr><th style="text-wrap: nowrap; max-width:192px; overflow:auto">A2<br />Int64</th><th style="text-wrap: nowrap; max-width:192px; overflow:auto">B<br />Utf8</th></tr></thead>
140+
<thead><tr><th {TH_STYLE}>A2<br />Int64</th><th {TH_STYLE}>B<br />Utf8</th></tr></thead>
140141
</table>
141142
<small>(No data to display: Dataframe not materialized)</small>
142143
</div>"""
@@ -162,7 +163,7 @@ def test_alias_repr(make_df):
162163
df._repr_html_()
163164
== f"""<div>
164165
<table class="dataframe">
165-
<thead><tr><th style="text-wrap: nowrap; max-width:192px; overflow:auto">A2<br />Int64</th><th style="text-wrap: nowrap; max-width:192px; overflow:auto">B<br />Utf8</th></tr></thead>
166+
<thead><tr><th {TH_STYLE}>A2<br />Int64</th><th {TH_STYLE}>B<br />Utf8</th></tr></thead>
166167
<tbody>
167168
<tr><td><div {TD_STYLE}>1</div></td><td><div {TD_STYLE}>a</div></td></tr>
168169
<tr><td><div {TD_STYLE}>2</div></td><td><div {TD_STYLE}>b</div></td></tr>
@@ -189,15 +190,15 @@ def test_repr_with_unicode(make_df, data_source):
189190
}
190191

191192
string_array = ["🔥a", "b🔥", "🦁🔥" * 60] # we dont truncate for html
192-
expected_html_unmaterialized = """<div>
193+
expected_html_unmaterialized = f"""<div>
193194
<table class="dataframe">
194-
<thead><tr><th style="text-wrap: nowrap; max-width:192px; overflow:auto">🔥<br />Int64</th><th style="text-wrap: nowrap; max-width:192px; overflow:auto">🦁<br />Utf8</th></tr></thead>
195+
<thead><tr><th {TH_STYLE}>🔥<br />Int64</th><th {TH_STYLE}>🦁<br />Utf8</th></tr></thead>
195196
</table>
196197
<small>(No data to display: Dataframe not materialized)</small>
197198
</div>"""
198199
expected_html_materialized = f"""<div>
199200
<table class="dataframe">
200-
<thead><tr><th style="text-wrap: nowrap; max-width:192px; overflow:auto">🔥<br />Int64</th><th style="text-wrap: nowrap; max-width:192px; overflow:auto">🦁<br />Utf8</th></tr></thead>
201+
<thead><tr><th {TH_STYLE}>🔥<br />Int64</th><th {TH_STYLE}>🦁<br />Utf8</th></tr></thead>
201202
<tbody>
202203
<tr><td><div {TD_STYLE}>1</div></td><td><div {TD_STYLE}>{string_array[0]}</div></td></tr>
203204
<tr><td><div {TD_STYLE}>2</div></td><td><div {TD_STYLE}>{string_array[1]}</div></td></tr>

0 commit comments

Comments
 (0)