Skip to content

Commit

Permalink
BUG: handling of array-like DataFrame elements in to_csv, make isnull…
Browse files Browse the repository at this point in the history
… work on lists of strings. close #1791
  • Loading branch information
wesm committed Sep 9, 2012
1 parent 5fba03b commit 553a2a9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions RELEASE.rst
Expand Up @@ -126,6 +126,8 @@ pandas 0.9.0
- Prevent segfault due to MultiIndex not being supported in HDFStore table
format (#1848)
- Fix UnboundLocalError in Panel.__setitem__ and add better error (#1826)
- Fix to_csv issues with list of string entries. Isnull works on list of
strings now too (#1791)

pandas 0.8.1
============
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/common.py
Expand Up @@ -73,9 +73,13 @@ def _isnull_ndarraylike(obj):
if values.dtype.kind in ('O', 'S'):
# Working around NumPy ticket 1542
shape = values.shape
result = np.empty(shape, dtype=bool)
vec = lib.isnullobj(values.ravel())
result[:] = vec.reshape(shape)

if values.dtype.kind == 'S':
result = np.zeros(values.shape, dtype=bool)
else:
result = np.empty(shape, dtype=bool)
vec = lib.isnullobj(values.ravel())
result[:] = vec.reshape(shape)

if isinstance(obj, Series):
result = Series(result, index=obj.index, copy=False)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Expand Up @@ -1088,7 +1088,7 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None,
row_fields = list(idx)
for i, col in enumerate(cols):
val = series[col][j]
if isnull(val):
if lib.checknull(val):
val = na_rep
if float_format is not None and com.is_float(val):
val = float_format % val
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_common.py
Expand Up @@ -50,6 +50,10 @@ def test_isnull_lists():
exp = np.array([[False], [False]])
assert(np.array_equal(result, exp))

# list of strings
result = isnull(['foo', 'bar'])
assert(not result.any())

def test_isnull_datetime():
assert (not isnull(datetime.now()))
assert notnull(datetime.now())
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_series.py
Expand Up @@ -2028,6 +2028,14 @@ def test_to_csv_float_format(self):
assert_series_equal(rs, xp)
os.remove(filename)

def test_to_csv_list_entries(self):
s = Series(['jack and jill','jesse and frank'])

split = s.str.split(r'\s+and\s+')

buf = StringIO()
split.to_csv(buf)

def test_clip(self):
val = self.ts.median()

Expand Down

0 comments on commit 553a2a9

Please sign in to comment.