Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class BufferedReader(object):
"""

def __init__(self, fh, delimiter=','):
pass
pass # pragma: no coverage

class BufferedCSVReader(BufferedReader):
pass
Expand Down Expand Up @@ -358,7 +358,7 @@ def _get_index_name(self):

def get_chunk(self, rows=None):
if rows is not None and self.skip_footer:
print 'skip_footer not supported for iteration'
raise ValueError('skip_footer not supported for iteration')

try:
content = self._get_lines(rows)
Expand Down
28 changes: 4 additions & 24 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class HDFStore(object):

``'r'``
Read-only; no data can be modified.
``'w``'
``'w'``
Write; a new file is created (an existing file with the same
name would be deleted).
``'a'``
Expand Down Expand Up @@ -337,22 +337,6 @@ def _write_frame(self, group, df):
def _read_frame(self, group, where=None):
return DataFrame(self._read_block_manager(group))

def _write_long(self, group, panel):
if len(panel.values) == 0:
raise ValueError('Can not write empty structure, data length was 0')
self._write_block_manager(group, panel._data)

def _read_long(self, group, where=None):
items = self._read_index(group, 'items')
major_axis = self._read_index(group, 'major_axis')
minor_axis = self._read_index(group, 'minor_axis')
major_labels = _read_array(group, 'major_labels')
minor_labels = _read_array(group, 'minor_labels')
values = _read_array(group, 'values')
index = MultiIndex(levels=[major_axis, minor_axis],
labels=[major_labels, minor_labels])
return DataFrame(values, index=index, columns=items)

def _write_block_manager(self, group, data):
if not data.is_consolidated():
data = data.consolidate()
Expand Down Expand Up @@ -433,10 +417,7 @@ def _write_index(self, group, key, index):
node._v_attrs.name = index.name

def _read_index(self, group, key):
try:
variety = getattr(group._v_attrs, '%s_variety' % key)
except Exception:
variety = 'regular'
variety = getattr(group._v_attrs, '%s_variety' % key)

if variety == 'multi':
return self._read_multi_index(group, key)
Expand Down Expand Up @@ -488,11 +469,10 @@ def _read_multi_index(self, group, key):
def _read_index_node(self, node):
data = node[:]
kind = node._v_attrs.kind
name = None

try:
if 'name' in node._v_attrs:
name = node._v_attrs.name
except Exception:
name = None

index = Index(_unconvert_index(data, kind))
index.name = name
Expand Down
22 changes: 21 additions & 1 deletion pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_custom_na_values(self):
skiprows=[1])
assert_almost_equal(df2.values, expected)


def test_skiprows_bug(self):
# GH #505
text = """#foo,a,b,c
Expand Down Expand Up @@ -293,9 +294,18 @@ def test_read_chunksize(self):
assert_frame_equal(chunks[1], df[2:4])
assert_frame_equal(chunks[2], df[4:])

def test_read_text_list(self):
data = """A,B,C\nfoo,1,2,3\nbar,4,5,6"""
as_list = [['A','B','C'],['foo','1','2','3'],['bar','4','5','6']]
df = read_csv(StringIO(data), index_col=0)

parser = TextParser(as_list, index_col=0, chunksize=2)
chunk = parser.get_chunk(None)

assert_frame_equal(chunk, df)

def test_iterator(self):
reader = read_csv(StringIO(self.data1), index_col=0, iterator=True)

df = read_csv(StringIO(self.data1), index_col=0)

chunk = reader.get_chunk(3)
Expand All @@ -315,6 +325,16 @@ def test_iterator(self):
assert_frame_equal(chunks[1], df[2:4])
assert_frame_equal(chunks[2], df[4:])

# pass skiprows
parser = TextParser(lines, index_col=0, chunksize=2, skiprows=[1])
chunks = list(parser)
assert_frame_equal(chunks[0], df[1:3])

# test bad parameter (skip_footer)
reader = read_csv(StringIO(self.data1), index_col=0, iterator=True,
skip_footer=True)
self.assertRaises(ValueError, reader.get_chunk, 3)

treader = read_table(StringIO(self.data1), sep=',', index_col=0,
iterator=True)
self.assert_(isinstance(treader, TextParser))
Expand Down
6 changes: 1 addition & 5 deletions pandas/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,10 @@ def add_suffix(self, suffix):

def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix=''):
if on is not None:
return self._join_on(other, on, how, lsuffix, rsuffix)
raise NotImplementedError
else:
return self._join_index(other, how, lsuffix, rsuffix)

def _join_on(self, other, on, how, lsuffix, rsuffix):
# need to implement?
raise NotImplementedError

def _join_index(self, other, how, lsuffix, rsuffix):
if isinstance(other, Series):
assert(other.name is not None)
Expand Down
11 changes: 11 additions & 0 deletions pandas/sparse/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def test_astype(self):

self.assertRaises(Exception, self.arr.astype, 'i8')

def test_copy_shallow(self):
arr2 = self.arr.copy(deep=False)

def _get_base(values):
base = values.base
while base.base is not None:
base = base.base
return base

assert(_get_base(arr2) is _get_base(self.arr))

def test_values_asarray(self):
assert_almost_equal(self.arr.values, self.arr_data)
assert_almost_equal(self.arr.to_dense(), self.arr_data)
Expand Down
10 changes: 10 additions & 0 deletions pandas/sparse/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ def _check(values, index1, index2, fill_value):
expected = expected.reindex(int_indices2).fillna(fill_value)
assert_almost_equal(expected.values, reindexed.sp_values)

# make sure level argument asserts
expected = expected.reindex(int_indices2).fillna(fill_value)

def _check_with_fill_value(values, first, second, fill_value=nan):
i_index1 = IntIndex(length, first)
i_index2 = IntIndex(length, second)
Expand Down Expand Up @@ -718,6 +721,9 @@ def test_constructor(self):
reindexed = self.frame.reindex(idx)
assert_sp_frame_equal(cons, reindexed)

# assert level parameter breaks reindex
self.assertRaises(Exception, self.frame.reindex, idx, level=0)

def test_constructor_ndarray(self):
# no index or columns
sp = SparseDataFrame(self.frame.values)
Expand All @@ -727,6 +733,10 @@ def test_constructor_ndarray(self):
columns=['A'])
assert_sp_frame_equal(sp, self.frame.reindex(columns=['A']))

# raise on level argument
self.assertRaises(Exception, self.frame.reindex, columns=['A'],
level=1)

# wrong length index / columns
self.assertRaises(Exception, SparseDataFrame, self.frame.values,
index=self.frame.index[:-1])
Expand Down