|
15 | 15 | import warnings
|
16 | 16 |
|
17 | 17 | import numpy as np
|
| 18 | +import pandas |
18 | 19 | from pandas import (Series, TimeSeries, DataFrame, Panel, Panel4D, Index,
|
19 | 20 | MultiIndex, Int64Index, Timestamp)
|
20 | 21 | from pandas.sparse.api import SparseSeries, SparseDataFrame, SparsePanel
|
@@ -1379,11 +1380,7 @@ def update_info(self, info):
|
1379 | 1380 | for key in self._info_fields:
|
1380 | 1381 |
|
1381 | 1382 | value = getattr(self, key, None)
|
1382 |
| - |
1383 |
| - try: |
1384 |
| - idx = info[self.name] |
1385 |
| - except: |
1386 |
| - idx = info[self.name] = dict() |
| 1383 | + idx = _get_info(info, self.name) |
1387 | 1384 |
|
1388 | 1385 | existing_value = idx.get(key)
|
1389 | 1386 | if key in idx and value is not None and existing_value != value:
|
@@ -2783,7 +2780,10 @@ def validate_data_columns(self, data_columns, min_itemsize):
|
2783 | 2780 | if not len(self.non_index_axes):
|
2784 | 2781 | return []
|
2785 | 2782 |
|
2786 |
| - axis_labels = self.non_index_axes[0][1] |
| 2783 | + axis, axis_labels = self.non_index_axes[0] |
| 2784 | + info = self.info.get(axis,dict()) |
| 2785 | + if info.get('type') == 'MultiIndex' and data_columns is not None: |
| 2786 | + raise ValueError("cannot use a multi-index on axis [{0}] with data_columns".format(axis)) |
2787 | 2787 |
|
2788 | 2788 | # evaluate the passed data_columns, True == use all columns
|
2789 | 2789 | # take only valide axis labels
|
@@ -2879,6 +2879,11 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None, data_columns=None,
|
2879 | 2879 | if sorted(append_axis) == sorted(exist_axis):
|
2880 | 2880 | append_axis = exist_axis
|
2881 | 2881 |
|
| 2882 | + # the non_index_axes info |
| 2883 | + info = _get_info(self.info,i) |
| 2884 | + info['names'] = list(a.names) |
| 2885 | + info['type'] = a.__class__.__name__ |
| 2886 | + |
2882 | 2887 | self.non_index_axes.append((i, append_axis))
|
2883 | 2888 |
|
2884 | 2889 | # set axis positions (based on the axes)
|
@@ -3459,10 +3464,20 @@ def read(self, where=None, columns=None, **kwargs):
|
3459 | 3464 | if not self.read_axes(where=where, **kwargs):
|
3460 | 3465 | return None
|
3461 | 3466 |
|
| 3467 | + info = self.info.get(self.non_index_axes[0][0],dict()) if len(self.non_index_axes) else dict() |
3462 | 3468 | index = self.index_axes[0].values
|
3463 | 3469 | frames = []
|
3464 | 3470 | for a in self.values_axes:
|
3465 |
| - cols = Index(a.values) |
| 3471 | + |
| 3472 | + # we could have a multi-index constructor here |
| 3473 | + # _ensure_index doesn't recognized our list-of-tuples here |
| 3474 | + if info.get('type') == 'MultiIndex': |
| 3475 | + cols = MultiIndex.from_tuples(a.values) |
| 3476 | + else: |
| 3477 | + cols = Index(a.values) |
| 3478 | + names = info.get('names') |
| 3479 | + if names is not None: |
| 3480 | + cols.set_names(names,inplace=True) |
3466 | 3481 |
|
3467 | 3482 | if self.is_transposed:
|
3468 | 3483 | values = a.cvalues
|
@@ -3657,6 +3672,14 @@ class AppendableNDimTable(AppendablePanelTable):
|
3657 | 3672 | obj_type = Panel4D
|
3658 | 3673 |
|
3659 | 3674 |
|
| 3675 | +def _get_info(info, name): |
| 3676 | + """ get/create the info for this name """ |
| 3677 | + try: |
| 3678 | + idx = info[name] |
| 3679 | + except: |
| 3680 | + idx = info[name] = dict() |
| 3681 | + return idx |
| 3682 | + |
3660 | 3683 | def _convert_index(index, encoding=None):
|
3661 | 3684 | index_name = getattr(index, 'name', None)
|
3662 | 3685 |
|
|
0 commit comments