Skip to content

Commit 61ece3b

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

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ I/O
12691269
- Bug in :meth:`DataFrame.to_dict` raises unnecessary ``UserWarning`` when columns are not unique and ``orient='tight'``. (:issue:`58281`)
12701270
- Bug in :meth:`DataFrame.to_excel` when writing empty :class:`DataFrame` with :class:`MultiIndex` on both axes (:issue:`57696`)
12711271
- Bug in :meth:`DataFrame.to_excel` where the :class:`MultiIndex` index with a period level was not a date (:issue:`60099`)
1272+
- 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`)
12721273
- Bug in :meth:`DataFrame.to_stata` when exporting a column containing both long strings (Stata strL) and :class:`pd.NA` values (:issue:`23633`)
12731274
- Bug in :meth:`DataFrame.to_stata` when input encoded length and normal length are mismatched (:issue:`61583`)
12741275
- Bug in :meth:`DataFrame.to_stata` when writing :class:`DataFrame` and ``byteorder=`big```. (:issue:`58969`)

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,3 +1165,17 @@ 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

0 commit comments

Comments
 (0)