Beispiel #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 = 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
        elif index_names[0] is None:
            index_names = ['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
Beispiel #2
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
Beispiel #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
Beispiel #4
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()
     return tz
Beispiel #5
0
 def test_utc_z_designator(self):
     self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z').tzinfo), 'UTC')
Beispiel #6
0
 def test_utc_z_designator(self):
     self.assertEqual(get_timezone(Timestamp("2014-11-02 01:00Z").tzinfo), "UTC")
Beispiel #7
0
 def test_utc_z_designator(self):
     self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z').tzinfo),
                      'UTC')
Beispiel #8
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()
     return tz
Beispiel #9
0
 def _infer(a, b):
     tz = a.tzinfo
     if b and b.tzinfo:
         assert(tslib.get_timezone(tz) == tslib.get_timezone(b.tzinfo))
     return tz
Beispiel #10
0
 def _infer(a, b):
     tz = a.tzinfo
     if b and b.tzinfo:
         assert(tslib.get_timezone(tz) == tslib.get_timezone(b.tzinfo))
     return tz