Skip to content

Commit 85d39a2

Browse files
committed
Add test
1 parent 2547ff3 commit 85d39a2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pandas/tests/io/formats/test_to_csv.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
from zipfile import ZipFile
5+
from datetime import datetime, timezone
56

67
from _csv import Error
78
import numpy as np
@@ -713,6 +714,30 @@ def test_to_csv_encoding_binary_handle(self, mode):
713714
assert handle.read().startswith(b'\xef\xbb\xbf""')
714715

715716

717+
"""
718+
tz-aware timestamps with/without microseconds should be written consistently
719+
Checks if the .ffffff format is consistent, even when microseconds==0
720+
721+
GH 62111
722+
"""
723+
def test_to_csv_tz_aware_consistent_microseconds_formatting_python_datetime(self):
724+
df = DataFrame({"timestamp": [
725+
datetime(2025, 8, 14, 12, 34, 56, 0, tzinfo=timezone.utc),
726+
datetime(2025, 8, 14, 12, 34, 56, 1, tzinfo=timezone.utc),
727+
]})
728+
with tm.ensure_clean("test.csv") as path:
729+
df.to_csv(path, index=False, lineterminator="\n")
730+
with open(path, encoding="utf-8") as f:
731+
contents = f.read()
732+
733+
#
734+
expected = (
735+
"timestamp\n"
736+
"2025-08-14 12:34:56.000000+00:00\n"
737+
"2025-08-14 12:34:56.000001+00:00\n"
738+
)
739+
assert contents == expected
740+
716741
def test_to_csv_iterative_compression_name(compression):
717742
# GH 38714
718743
df = DataFrame(

0 commit comments

Comments
 (0)