Skip to content

Commit f354548

Browse files
committed
Merge pull request #3625 from jreback/to_csv
BUG: Fix not consolidating before to_csv (GH3624_)
2 parents a026561 + b91da38 commit f354548

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pandas 0.11.1
124124
- Fix indexing issue in ndim >= 3 with ``iloc`` (GH3617_)
125125
- Correctly parse date columns with embedded (nan/NaT) into datetime64[ns] dtype in ``read_csv``
126126
when ``parse_dates`` is specified (GH3062_)
127+
- Fix not consolidating before to_csv (GH3624_)
127128

128129
.. _GH3164: https://github.com/pydata/pandas/issues/3164
129130
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -175,6 +176,7 @@ pandas 0.11.1
175176
.. _GH3435: https://github.com/pydata/pandas/issues/3435
176177
.. _GH3611: https://github.com/pydata/pandas/issues/3611
177178
.. _GH3062: https://github.com/pydata/pandas/issues/3062
179+
.. _GH3624: https://github.com/pydata/pandas/issues/3624
178180
.. _GH1512: https://github.com/pydata/pandas/issues/1512
179181

180182

pandas/core/format.py

+2
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ def __init__(self, obj, path_or_buf, sep=",", na_rep='', float_format=None,
777777
line_terminator='\n', chunksize=None, engine=None):
778778

779779
self.engine = engine # remove for 0.12
780+
781+
obj._consolidate_inplace()
780782
self.obj = obj
781783

782784
self.path_or_buf = path_or_buf

pandas/tests/test_frame.py

+13
Original file line numberDiff line numberDiff line change
@@ -4939,6 +4939,19 @@ def test_to_csv_from_csv_w_all_infs(self):
49394939
assert_frame_equal(self.frame, recons, check_names=False) # TODO to_csv drops column name
49404940
assert_frame_equal(np.isinf(self.frame), np.isinf(recons), check_names=False)
49414941

4942+
def test_to_csv_no_index(self):
4943+
# GH 3624, after appending columns, to_csv fails
4944+
pname = '__tmp_to_csv_no_index__'
4945+
with ensure_clean(pname) as path:
4946+
df = DataFrame({'c1':[1,2,3], 'c2':[4,5,6]})
4947+
df.to_csv(path, index=False)
4948+
result = read_csv(path)
4949+
assert_frame_equal(df,result)
4950+
df['c3'] = [7,8,9]
4951+
df.to_csv(path, index=False)
4952+
result = read_csv(path)
4953+
assert_frame_equal(df,result)
4954+
49424955
def test_to_csv_multiindex(self):
49434956

49444957
pname = '__tmp_to_csv_multiindex__'

0 commit comments

Comments
 (0)