Skip to content

fixed row/col orientation for 2D arrays #1834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2012
Merged
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
28 changes: 20 additions & 8 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,10 @@ def _read_index_node(self, node):
def _write_array(self, group, key, value):
if key in group:
self.handle.removeNode(group, key)


#Transform needed to interface with pytables row/col notation
value = value.T

if self.filters is not None:
atom = None
try:
Expand All @@ -701,6 +704,7 @@ def _write_array(self, group, key, value):
value.shape,
filters=self.filters)
ca[:] = value
getattr(group, key)._v_attrs.transposed = True
return

if value.dtype.type == np.object_:
Expand All @@ -719,6 +723,8 @@ def _write_array(self, group, key, value):
getattr(group, key)._v_attrs.shape = value.shape
else:
self.handle.createArray(group, key, value)

getattr(group, key)._v_attrs.transposed = True

def _write_table(self, group, items=None, index=None, columns=None,
values=None, append=False, compression=None):
Expand Down Expand Up @@ -958,23 +964,29 @@ def _read_array(group, key):
import tables
node = getattr(group, key)
data = node[:]
attrs = node._v_attrs

transposed = getattr(attrs, 'transposed', False)

if isinstance(node, tables.VLArray):
return data[0]
ret = data[0]
else:
attrs = node._v_attrs

dtype = getattr(attrs, 'value_type', None)
shape = getattr(attrs, 'shape', None)

if shape is not None:
# length 0 axis
return np.empty(shape, dtype=dtype)
ret = np.empty(shape, dtype=dtype)

if dtype == 'datetime64':
return np.array(data, dtype='M8[ns]')
return data

ret = np.array(data, dtype='M8[ns]')
ret = data

if transposed == True:
return ret.T
else:
return ret

def _unconvert_index(data, kind):
if kind == 'datetime64':
index = DatetimeIndex(data)
Expand Down