Skip to content

Commit 0718d05

Browse files
committed
Merge pull request pandas-dev#106 from manahl/fix_pandas_panel_storage
Fix pd.Panel storage.
2 parents 3cf3153 + 52b5b3f commit 0718d05

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 1.21 (2016-03-08)
4+
5+
* Bugfix: #106 Fix Pandas Panel storage for panels with different dimensions
6+
37
### 1.20 (2016-02-03)
48

59
* Feature: #98 Add initial_image as optional parameter on tickstore write()

arctic/store/_pandas_ndarray_store.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class PandasPanelStore(PandasDataFrameStore):
316316

317317
def can_write(self, version, symbol, data):
318318
if isinstance(data, Panel):
319-
frame = data.to_frame()
319+
frame = data.to_frame(filter_observations=False)
320320
if np.any(frame.dtypes.values == 'object'):
321321
return self.can_convert_to_records_without_objects(frame, symbol)
322322
return True
@@ -329,7 +329,7 @@ def write(self, arctic_lib, version, symbol, item, previous_version):
329329
raise ValueError('Cannot insert a zero size panel into mongo.')
330330
if not np.all(len(i.names) == 1 for i in item.axes):
331331
raise ValueError('Cannot insert panels with multiindexes')
332-
item = item.to_frame()
332+
item = item.to_frame(filter_observations=False)
333333
if len(set(item.dtypes)) == 1:
334334
# If all columns have the same dtype, we support non-string column names.
335335
# We know from above check that columns is not a multiindex.

tests/integration/store/test_pandas_store.py

+15
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,21 @@ def test_panel_save_read(library, df_size):
538538
str(pn.axes[i].names) + "!=" + str(pn.axes[i].names)
539539

540540

541+
def test_panel_save_read_with_nans(library):
542+
'''Ensure that nan rows are not dropped when calling to_frame.'''
543+
df1 = DataFrame(data=np.arange(4).reshape((2, 2)), index=['r1', 'r2'], columns=['c1', 'c2'])
544+
df2 = DataFrame(data=np.arange(6).reshape((3, 2)), index=['r1', 'r2', 'r3'], columns=['c1', 'c2'])
545+
p_in = Panel(data=dict(i1=df1, i2=df2))
546+
547+
library.write('pandas', p_in)
548+
p_out = library.read('pandas').data
549+
550+
assert p_in.shape == p_out.shape
551+
# check_names is False because pandas helpfully names the axes for us.
552+
assert_frame_equal(p_in.iloc[0], p_out.iloc[0], check_names=False)
553+
assert_frame_equal(p_in.iloc[1], p_out.iloc[1], check_names=False)
554+
555+
541556
def test_save_read_ints(library):
542557
ts1 = DataFrame(index=[dt(2012, 1, 1) + dtd(hours=x) for x in range(5)],
543558
data={'col1':np.arange(5), 'col2':np.arange(5)})

tests/unit/store/test_pandas_ndarray_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_panel_converted_to_dataframe_and_stacked_to_write():
6363
with patch.object(PandasDataFrameStore, 'write') as mock_write:
6464
with patch('arctic.store._pandas_ndarray_store.DataFrame') as DF:
6565
store.write(sentinel.mlib, sentinel.version, sentinel.symbol, panel, sentinel.prev)
66-
panel.to_frame.assert_called_with()
66+
panel.to_frame.assert_called_with(filter_observations=False)
6767
DF.assert_called_with(panel.to_frame.return_value.stack.return_value)
6868
mock_write.assert_called_with(sentinel.mlib, sentinel.version, sentinel.symbol,
6969
DF.return_value, sentinel.prev)

0 commit comments

Comments
 (0)