Skip to content

Commit

Permalink
BUG/API: (GH4584) to_hdf was raising when passing both arguments appe…
Browse files Browse the repository at this point in the history
…nd and table
  • Loading branch information
jreback committed Aug 24, 2013
1 parent 209e248 commit 7d636b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
with a different block ordering (:issue:`4096`)
- ``read_hdf`` was not respecting as passed ``mode`` (:issue:`4504`)
- appending a 0-len table will work correctly (:issue:`4273`)
- ``to_hdf`` was raising when passing both arguments ``append`` and ``table`` (:issue:`4584`)
- Fixed bug in tslib.tz_convert(vals, tz1, tz2): it could raise IndexError exception while
trying to access trans[pos + 1] (:issue:`4496`)
- The ``by`` argument now works correctly with the ``layout`` argument
Expand Down
6 changes: 4 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def remove(self, key, where=None, start=None, stop=None):
raise ValueError('can only remove with where on objects written as tables')
return s.delete(where = where, start=start, stop=stop)

def append(self, key, value, columns=None, **kwargs):
def append(self, key, value, columns=None, append=True, **kwargs):
"""
Append to Table in file. Node must already exist and be Table
format.
Expand All @@ -699,6 +699,7 @@ def append(self, key, value, columns=None, **kwargs):
----------
key : object
value : {Series, DataFrame, Panel, Panel4D}
append : boolean, default True, append the input data to the existing
data_columns : list of columns to create as data columns, or True to use all columns
min_itemsize : dict of columns that specify minimum string sizes
nan_rep : string to use as string nan represenation
Expand All @@ -714,7 +715,8 @@ def append(self, key, value, columns=None, **kwargs):
if columns is not None:
raise Exception("columns is not a supported keyword in append, try data_columns")

self._write_to_group(key, value, table=True, append=True, **kwargs)
kwargs['table'] = True
self._write_to_group(key, value, append=append, **kwargs)

def append_to_multiple(self, d, value, selector, data_columns=None, axes=None, **kwargs):
"""
Expand Down
34 changes: 34 additions & 0 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,40 @@ def roundtrip(key, obj,**kwargs):
finally:
safe_remove(self.path)

def test_api(self):

# GH4584
# API issue when to_hdf doesn't acdept append AND table args
with tm.ensure_clean(self.path) as path:

df = tm.makeDataFrame()
df.iloc[:10].to_hdf(path,'df',append=True,table=True)
df.iloc[10:].to_hdf(path,'df',append=True,table=True)
assert_frame_equal(read_hdf(path,'df'),df)

# append to False
df.iloc[:10].to_hdf(path,'df',append=False,table=True)
df.iloc[10:].to_hdf(path,'df',append=True,table=True)
assert_frame_equal(read_hdf(path,'df'),df)

with tm.ensure_clean(self.path) as path:

df = tm.makeDataFrame()
df.to_hdf(path,'df',append=False,table=False)
assert_frame_equal(read_hdf(path,'df'),df)

with ensure_clean(self.path) as store:

df = tm.makeDataFrame()
store.append('df',df.iloc[:10],append=True,table=True)
store.append('df',df.iloc[10:],append=True,table=True)
assert_frame_equal(read_hdf(path,'df'),df)

# append to False
store.append('df',df.iloc[:10],append=False,table=True)
store.append('df',df.iloc[10:],append=True,table=True)
assert_frame_equal(read_hdf(path,'df'),df)

def test_keys(self):

with ensure_clean(self.path) as store:
Expand Down

0 comments on commit 7d636b0

Please sign in to comment.