From 11de0d24b368f29083067de95c0707afa4368b0f Mon Sep 17 00:00:00 2001 From: hugo Date: Sat, 22 Aug 2015 15:34:23 -0400 Subject: [PATCH 1/2] wip --- pandas/io/pytables.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 8ef6363f836ae..dc7d5ba45837c 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2100,6 +2100,7 @@ def get_attr(self): def set_attr(self): """ set the data for this colummn """ + import pdb;pdb.set_trace() setattr(self.attrs, self.kind_attr, self.values) setattr(self.attrs, self.meta_attr, self.meta) if self.dtype is not None: @@ -3061,12 +3062,19 @@ def set_info(self): """ update our table index info """ self.attrs.info = self.info + def set_non_index_axes(self): + for dim, flds in self.non_index_axes: + name = "non_index_axes_%d" % dim + self._handle.create_carray(self.attrs._v_node._v_pathname, name, obj=np.array(flds)) + def set_attrs(self): """ set our table type & indexables """ self.attrs.table_type = str(self.table_type) self.attrs.index_cols = self.index_cols() self.attrs.values_cols = self.values_cols() - self.attrs.non_index_axes = self.non_index_axes + + #self.attrs.non_index_axes = self.non_index_axes + self.set_non_index_axes() self.attrs.data_columns = self.data_columns self.attrs.nan_rep = self.nan_rep self.attrs.encoding = self.encoding From 143985aa3140d902c42015f86af2f61ffefd50ed Mon Sep 17 00:00:00 2001 From: hugo Date: Sat, 22 Aug 2015 16:03:13 -0400 Subject: [PATCH 2/2] wip --- pandas/io/pytables.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index dc7d5ba45837c..80037f0b891ef 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -11,7 +11,8 @@ import itertools import warnings import os - +from six import string_types +from tables.exceptions import NoSuchNodeError import numpy as np from pandas import (Series, TimeSeries, DataFrame, Panel, Panel4D, Index, MultiIndex, Int64Index, Timestamp) @@ -1478,6 +1479,7 @@ def infer(self, handler): """infer this column from the table: create and return a new object""" table = handler.table new_self = self.copy() + new_self._handle = handler._handle new_self.set_table(table) new_self.get_attr() new_self.read_metadata(handler) @@ -1557,6 +1559,7 @@ def validate_names(self): pass def validate_and_set(self, handler, append, **kwargs): + self._handle = handler._handle self.set_table(handler.table) self.validate_col() self.validate_attr(append) @@ -2094,14 +2097,22 @@ def convert(self, values, nan_rep, encoding): def get_attr(self): """ get the data for this colummn """ self.values = getattr(self.attrs, self.kind_attr, None) + if self.values is None: + try: + self.values = self._handle.get_node(self.attrs._v_node._v_parent, + self.kind_attr)[:].tolist() + except NoSuchNodeError: + pass self.dtype = getattr(self.attrs, self.dtype_attr, None) self.meta = getattr(self.attrs, self.meta_attr, None) self.set_kind() def set_attr(self): """ set the data for this colummn """ - import pdb;pdb.set_trace() - setattr(self.attrs, self.kind_attr, self.values) + #setattr(self.attrs, self.kind_attr, self.values) + self._handle.create_carray(self.attrs._v_node._v_parent, + self.kind_attr, + obj=np.array(self.values)) setattr(self.attrs, self.meta_attr, self.meta) if self.dtype is not None: setattr(self.attrs, self.dtype_attr, self.dtype) @@ -3063,9 +3074,21 @@ def set_info(self): self.attrs.info = self.info def set_non_index_axes(self): + replacement = [] for dim, flds in self.non_index_axes: name = "non_index_axes_%d" % dim - self._handle.create_carray(self.attrs._v_node._v_pathname, name, obj=np.array(flds)) + self._handle.create_carray(self.attrs._v_node, name, obj=np.array(flds)) + replacement.append((dim, name)) + self.attrs.non_index_axes = replacement + + def get_non_index_axes(self): + non_index_axes = getattr(self.attrs, 'non_index_axes', []) + new = [] + for dim, flds in non_index_axes: + if isinstance(flds, string_types): + flds = self._handle.get_node(self.attrs._v_node, flds)[:].tolist() + new.append((dim, flds)) + return new def set_attrs(self): """ set our table type & indexables """ @@ -3084,8 +3107,7 @@ def set_attrs(self): def get_attrs(self): """ retrieve our attributes """ - self.non_index_axes = getattr( - self.attrs, 'non_index_axes', None) or [] + self.non_index_axes = self.get_non_index_axes() self.data_columns = getattr( self.attrs, 'data_columns', None) or [] self.info = getattr(