Skip to content

Commit 553a2a9

Browse files
committed
BUG: handling of array-like DataFrame elements in to_csv, make isnull work on lists of strings. close #1791
1 parent 5fba03b commit 553a2a9

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ pandas 0.9.0
126126
- Prevent segfault due to MultiIndex not being supported in HDFStore table
127127
format (#1848)
128128
- Fix UnboundLocalError in Panel.__setitem__ and add better error (#1826)
129+
- Fix to_csv issues with list of string entries. Isnull works on list of
130+
strings now too (#1791)
129131

130132
pandas 0.8.1
131133
============

pandas/core/common.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ def _isnull_ndarraylike(obj):
7373
if values.dtype.kind in ('O', 'S'):
7474
# Working around NumPy ticket 1542
7575
shape = values.shape
76-
result = np.empty(shape, dtype=bool)
77-
vec = lib.isnullobj(values.ravel())
78-
result[:] = vec.reshape(shape)
76+
77+
if values.dtype.kind == 'S':
78+
result = np.zeros(values.shape, dtype=bool)
79+
else:
80+
result = np.empty(shape, dtype=bool)
81+
vec = lib.isnullobj(values.ravel())
82+
result[:] = vec.reshape(shape)
7983

8084
if isinstance(obj, Series):
8185
result = Series(result, index=obj.index, copy=False)

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None,
10881088
row_fields = list(idx)
10891089
for i, col in enumerate(cols):
10901090
val = series[col][j]
1091-
if isnull(val):
1091+
if lib.checknull(val):
10921092
val = na_rep
10931093
if float_format is not None and com.is_float(val):
10941094
val = float_format % val

pandas/tests/test_common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def test_isnull_lists():
5050
exp = np.array([[False], [False]])
5151
assert(np.array_equal(result, exp))
5252

53+
# list of strings
54+
result = isnull(['foo', 'bar'])
55+
assert(not result.any())
56+
5357
def test_isnull_datetime():
5458
assert (not isnull(datetime.now()))
5559
assert notnull(datetime.now())

pandas/tests/test_series.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,14 @@ def test_to_csv_float_format(self):
20282028
assert_series_equal(rs, xp)
20292029
os.remove(filename)
20302030

2031+
def test_to_csv_list_entries(self):
2032+
s = Series(['jack and jill','jesse and frank'])
2033+
2034+
split = s.str.split(r'\s+and\s+')
2035+
2036+
buf = StringIO()
2037+
split.to_csv(buf)
2038+
20312039
def test_clip(self):
20322040
val = self.ts.median()
20332041

0 commit comments

Comments
 (0)