Skip to content

Commit 8ac1489

Browse files
author
Egor
committed
BUG: #10833 Added test and info to whatsnew
1 parent b5ad62c commit 8ac1489

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.17.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,3 +678,4 @@ Bug Fixes
678678
- Bug in ``iloc`` allowing memory outside bounds of a Series to be accessed with negative integers (:issue:`10779`)
679679
- Bug in ``read_msgpack`` where encoding is not respected (:issue:`10580`)
680680
- Bug preventing access to the first index when using ``iloc`` with a list containing the appropriate negative integer (:issue:`10547`, :issue:`10779`)
681+
- Bug in ``TimedeltaIndex`` formatter causing error while trying to save ``DataFrame`` with ``TimedeltaIndex`` using ``to_csv`` (:issue:`10833`)

pandas/tests/test_frame.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6308,7 +6308,6 @@ def test_to_csv_from_csv(self):
63086308
header=['AA', 'X'])
63096309

63106310
with ensure_clean(pname) as path:
6311-
import pandas as pd
63126311
df1 = DataFrame(np.random.randn(3, 1))
63136312
df2 = DataFrame(np.random.randn(3, 1))
63146313

@@ -6320,6 +6319,20 @@ def test_to_csv_from_csv(self):
63206319
xp.columns = lmap(int,xp.columns)
63216320
assert_frame_equal(xp,rs)
63226321

6322+
with ensure_clean() as path:
6323+
# GH 10833 (TimedeltaIndex formatting)
6324+
dt = pd.Timedelta(seconds=1)
6325+
df_orig = pd.DataFrame({'data': list(range(10))},
6326+
index=[i*dt for i in range(10)])
6327+
df_orig.index.rename('timestamp', inplace=True)
6328+
df_orig.to_csv(path)
6329+
6330+
df_test = pd.read_csv(path, index_col='timestamp')
6331+
df_test.index = pd.to_timedelta(df_test.index)
6332+
df_test.index.rename('timestamp', inplace=True)
6333+
6334+
self.assertTrue(df_test.equal(df_orig))
6335+
63236336
def test_to_csv_cols_reordering(self):
63246337
# GH3454
63256338
import pandas as pd

0 commit comments

Comments
 (0)