Skip to content

BUG: Fixes #54617 Dataframe to html for empty array with complex dtypes #54451

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

Merged
merged 15 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,8 @@ def _trim_zeros_complex(str_complexes: np.ndarray, decimal: str = ".") -> list[s
# in the array
n = len(str_complexes)
padded_parts = _trim_zeros_float(real_part + imag_part, decimal)
if len(padded_parts) == 0:
return []
padded_length = max(len(part) for part in padded_parts) - 1
padded = [
real_pt # real part, possibly NaN
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,14 @@ def test_to_html_tuple_col_with_colspace():
"</table>"
)
assert result == expected


def test_to_html_empty_complex_array():
# GH#54167
df = DataFrame({"x": np.array([], dtype="complex")})
html_op = df.to_html(col_space=100)
result = hashlib.md5(b"html_op").hexdigest()
expected = "9d81f92dbc2d9f2f4876900c09559c39"
#'<table border="1" class="dataframe">\n <thead>\n <tr style="text-align: right;">\n <th></th>\n <th>x</th>\n </tr>\n </thead>\n <tbody>\n </tbody>\n</table>'
print("--assserting")
assert result == expected