Skip to content

Commit 7d636b0

Browse files
committed
BUG/API: (GH4584) to_hdf was raising when passing both arguments append and table
1 parent 209e248 commit 7d636b0

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
200200
with a different block ordering (:issue:`4096`)
201201
- ``read_hdf`` was not respecting as passed ``mode`` (:issue:`4504`)
202202
- appending a 0-len table will work correctly (:issue:`4273`)
203+
- ``to_hdf`` was raising when passing both arguments ``append`` and ``table`` (:issue:`4584`)
203204
- Fixed bug in tslib.tz_convert(vals, tz1, tz2): it could raise IndexError exception while
204205
trying to access trans[pos + 1] (:issue:`4496`)
205206
- The ``by`` argument now works correctly with the ``layout`` argument

pandas/io/pytables.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def remove(self, key, where=None, start=None, stop=None):
690690
raise ValueError('can only remove with where on objects written as tables')
691691
return s.delete(where = where, start=start, stop=stop)
692692

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

717-
self._write_to_group(key, value, table=True, append=True, **kwargs)
718+
kwargs['table'] = True
719+
self._write_to_group(key, value, append=append, **kwargs)
718720

719721
def append_to_multiple(self, d, value, selector, data_columns=None, axes=None, **kwargs):
720722
"""

pandas/io/tests/test_pytables.py

+34
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,40 @@ def roundtrip(key, obj,**kwargs):
147147
finally:
148148
safe_remove(self.path)
149149

150+
def test_api(self):
151+
152+
# GH4584
153+
# API issue when to_hdf doesn't acdept append AND table args
154+
with tm.ensure_clean(self.path) as path:
155+
156+
df = tm.makeDataFrame()
157+
df.iloc[:10].to_hdf(path,'df',append=True,table=True)
158+
df.iloc[10:].to_hdf(path,'df',append=True,table=True)
159+
assert_frame_equal(read_hdf(path,'df'),df)
160+
161+
# append to False
162+
df.iloc[:10].to_hdf(path,'df',append=False,table=True)
163+
df.iloc[10:].to_hdf(path,'df',append=True,table=True)
164+
assert_frame_equal(read_hdf(path,'df'),df)
165+
166+
with tm.ensure_clean(self.path) as path:
167+
168+
df = tm.makeDataFrame()
169+
df.to_hdf(path,'df',append=False,table=False)
170+
assert_frame_equal(read_hdf(path,'df'),df)
171+
172+
with ensure_clean(self.path) as store:
173+
174+
df = tm.makeDataFrame()
175+
store.append('df',df.iloc[:10],append=True,table=True)
176+
store.append('df',df.iloc[10:],append=True,table=True)
177+
assert_frame_equal(read_hdf(path,'df'),df)
178+
179+
# append to False
180+
store.append('df',df.iloc[:10],append=False,table=True)
181+
store.append('df',df.iloc[10:],append=True,table=True)
182+
assert_frame_equal(read_hdf(path,'df'),df)
183+
150184
def test_keys(self):
151185

152186
with ensure_clean(self.path) as store:

0 commit comments

Comments
 (0)