Skip to content

Commit 05cf151

Browse files
committed
BUG: Fix to_html adding time to datetime columns in transposed DataFrame (GH#10640)
1 parent 7b51d3a commit 05cf151

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ I/O
12901290
- Bug in :meth:`read_csv` with ``engine="pyarrow"`` and ``dtype="Int64"`` losing precision (:issue:`56136`)
12911291
- Bug in :meth:`read_excel` raising ``ValueError`` when passing array of boolean values when ``dtype="boolean"``. (:issue:`58159`)
12921292
- Bug in :meth:`read_html` where ``rowspan`` in header row causes incorrect conversion to ``DataFrame``. (:issue:`60210`)
1293+
- Bug in :meth:`DataFrame.to_html` where a :class:`DatetimeIndex` in the columns was including the time even when it was 00:00:00 (:issue:`10640`)
12931294
- Bug in :meth:`read_json` ignoring the given ``dtype`` when ``engine="pyarrow"`` (:issue:`59516`)
12941295
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
12951296
- Bug in :meth:`read_json` where extreme value integers in string format were incorrectly parsed as a different integer number (:issue:`20608`)

pandas/io/formats/html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def row_levels(self) -> int:
130130
return 0
131131

132132
def _get_columns_formatted_values(self) -> Iterable:
133-
return self.columns
133+
return self.columns._format_flat(include_name=False)
134134

135135
@property
136136
def is_truncated(self) -> bool:

pandas/tests/io/formats/test_to_html.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,3 +1165,18 @@ def test_to_html_empty_complex_array():
11651165
"</table>"
11661166
)
11671167
assert result == expected
1168+
1169+
1170+
def test_to_html_datetime_columns_no_time():
1171+
# GH 10640
1172+
df = DataFrame(
1173+
np.random.default_rng(2).standard_normal((5, 2)),
1174+
columns=["a", "b"],
1175+
index=pd.to_datetime(
1176+
["2015-01-05", "2015-01-04", "2015-01-03", "2015-01-02", "2015-01-01"]
1177+
),
1178+
)
1179+
result = df.T.to_html()
1180+
assert "2015-01-05 00:00:00" not in result
1181+
assert "2015-01-05" in result
1182+

0 commit comments

Comments
 (0)