-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Error while saving DataFrame with TimedeltaIndex to .csv #10833 #10845
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6308,7 +6308,6 @@ def test_to_csv_from_csv(self): | |
header=['AA', 'X']) | ||
|
||
with ensure_clean(pname) as path: | ||
import pandas as pd | ||
df1 = DataFrame(np.random.randn(3, 1)) | ||
df2 = DataFrame(np.random.randn(3, 1)) | ||
|
||
|
@@ -6320,6 +6319,20 @@ def test_to_csv_from_csv(self): | |
xp.columns = lmap(int,xp.columns) | ||
assert_frame_equal(xp,rs) | ||
|
||
with ensure_clean() as path: | ||
# GH 10833 (TimedeltaIndex formatting) | ||
dt = pd.Timedelta(seconds=1) | ||
df_orig = pd.DataFrame({'data': list(range(10))}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call this |
||
index=[i*dt for i in range(10)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do |
||
df_orig.index.rename('timestamp', inplace=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we in general do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like there is no way to preserve index name using
Should I use this variant instead?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, no?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the same result as you on your piece of code. Take a look at this example:
Seems like it disappears during There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh i c. if you want to trace where that is not passed thru would be gr8. (if its easy do it as part of this issue, if not, pls open a new issue). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I'll finalize both issues within this week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gr8 thanks. Add a separate whatsnew note (with same issue number) for the name lost in conversion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say that casting |
||
df_orig.to_csv(path) | ||
|
||
df_test = pd.read_csv(path, index_col='timestamp') | ||
df_test.index = pd.to_timedelta(df_test.index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call this |
||
df_test.index.rename('timestamp', inplace=True) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set the index name for now so this issue is independent |
||
self.assertTrue(df_test.equal(df_orig)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could do this, but it is not nearly as imformative as |
||
|
||
def test_to_csv_cols_reordering(self): | ||
# GH3454 | ||
import pandas as pd | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a
Timedelta
column as well.