コード例 #1
0
    def _index_to_records(self, df):
        metadata = {}
        index = df.index

        if isinstance(index, MultiIndex):
            # array of tuples to numpy cols. copy copy copy
            if len(df) > 0:
                ix_vals = list(map(np.array, [index.get_level_values(i) for i in range(index.nlevels)]))
            else:
                # empty multi index has no size, create empty arrays for recarry..
                ix_vals = [np.array([]) for n in index.names]
        else:
            ix_vals = [index.values]

        count = 0
        index_names = list(index.names)
        if isinstance(index, MultiIndex):
            for i, n in enumerate(index_names):
                if n is None:
                    index_names[i] = 'level_%d' % count
                    count += 1
                    log.info("Level in MultiIndex has no name, defaulting to %s" % index_names[i])
        elif index_names[0] is None:
            index_names = ['index']
            log.info("Index has no name, defaulting to 'index'")

        metadata['index'] = index_names

        if isinstance(index, DatetimeIndex) and index.tz is not None:
            metadata['index_tz'] = get_timezone(index.tz)
        elif isinstance(index, MultiIndex):
            metadata['index_tz'] = [get_timezone(i.tz) if isinstance(i, DatetimeIndex) else None for i in index.levels]

        return index_names, ix_vals, metadata
コード例 #2
0
ファイル: tools.py プロジェクト: agartland/pandas
 def _infer(a, b):
     tz = a.tzinfo
     if b and b.tzinfo:
         if not (tslib.get_timezone(tz) == tslib.get_timezone(b.tzinfo)):
             raise AssertionError('Inputs must both have the same timezone,'
                                  ' {0} != {1}'.format(tz, b.tzinfo))
     return tz
コード例 #3
0
 def _infer(a, b):
     tz = a.tzinfo
     if b and b.tzinfo:
         if not (tslib.get_timezone(tz) == tslib.get_timezone(b.tzinfo)):
             raise AssertionError('Inputs must both have the same timezone,'
                                  ' {0} != {1}'.format(tz, b.tzinfo))
     return tz