Skip to content

Commit 784445c

Browse files
varunkumar-devjreback
authored andcommitted
BUG: pandas-dev#11637 fix to_csv incorrect output.
1 parent 243c219 commit 784445c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

doc/source/whatsnew/v0.17.1.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,8 @@ Bug Fixes
166166
- Bug in ``squeeze()`` with zero length arrays (:issue:`11230`, :issue:`8999`)
167167
- Bug in ``describe()`` dropping column names for hierarchical indexes (:issue:`11517`)
168168
- Bug in ``DataFrame.pct_change()`` not propagating ``axis`` keyword on ``.fillna`` method (:issue:`11150`)
169-
170-
171-
169+
- Bug in ``.to_csv()`` when a mix of integer and string column names are passed as the ``columns`` parameter (:issue:`11637`)
172170
- Bug in indexing with a ``range``, (:issue:`11652`)
173-
174-
175171
- Bug in ``to_sql`` using unicode column names giving UnicodeEncodeError with (:issue:`11431`).
176172
- Fix regression in setting of ``xticks`` in ``plot`` (:issue:`11529`).
177173
- Bug in ``holiday.dates`` where observance rules could not be applied to holiday and doc enhancement (:issue:`11477`, :issue:`11533`)

pandas/core/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='', float_format=None,
13271327
date_format=date_format,
13281328
quoting=self.quoting)
13291329
else:
1330-
cols = np.asarray(list(cols))
1330+
cols = list(cols)
13311331
self.obj = self.obj.loc[:, cols]
13321332

13331333
# update columns to include possible multiplicity of dupes
@@ -1339,7 +1339,7 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='', float_format=None,
13391339
date_format=date_format,
13401340
quoting=self.quoting)
13411341
else:
1342-
cols = np.asarray(list(cols))
1342+
cols = list(cols)
13431343

13441344
# save it
13451345
self.cols = cols

pandas/tests/test_frame.py

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from pandas.util.misc import is_little_endian
4040

4141
from pandas.util.testing import (assert_almost_equal,
42+
assert_equal,
4243
assert_numpy_array_equal,
4344
assert_series_equal,
4445
assert_frame_equal,
@@ -6989,6 +6990,15 @@ def test_to_csv_no_index(self):
69896990
result = read_csv(path)
69906991
assert_frame_equal(df,result)
69916992

6993+
def test_to_csv_with_mix_columns(self):
6994+
#GH11637, incorrect output when a mix of integer and string column
6995+
# names passed as columns parameter in to_csv
6996+
6997+
df = DataFrame({0: ['a', 'b', 'c'],
6998+
1: ['aa', 'bb', 'cc']})
6999+
df['test'] = 'txt'
7000+
assert_equal(df.to_csv(), df.to_csv(columns=[0, 1, 'test']))
7001+
69927002
def test_to_csv_headers(self):
69937003
# GH6186, the presence or absence of `index` incorrectly
69947004
# causes to_csv to have different header semantics.

0 commit comments

Comments
 (0)