Esempio n. 1
0
    def equals(self, other):
        """
        Determines if two Index objects contain the same elements.
        """
        if self is other:
            return True

        if (not hasattr(other, 'inferred_type') or
            other.inferred_type != 'datetime64'):
            if self.offset is not None:
                return False
            try:
                other = DatetimeIndex(other)
            except:
                return False

        if self.tz is not None:
            if other.tz is None:
                return False
            same_zone = lib.get_timezone(self.tz) == lib.get_timezone(other.tz)
        else:
            if other.tz is not None:
                return False
            same_zone = True

        return same_zone and np.array_equal(self.asi8, other.asi8)
Esempio n. 2
0
    def equals(self, other):
        """
        Determines if two Index objects contain the same elements.
        """
        if self is other:
            return True

        if (not hasattr(other, 'inferred_type')
                or other.inferred_type != 'datetime64'):
            if self.offset is not None:
                return False
            try:
                other = DatetimeIndex(other)
            except:
                return False

        if self.tz is not None:
            if other.tz is None:
                return False
            same_zone = lib.get_timezone(self.tz) == lib.get_timezone(other.tz)
        else:
            if other.tz is not None:
                return False
            same_zone = True

        return same_zone and np.array_equal(self.asi8, other.asi8)
Esempio n. 3
0
    def _write_index(self, group, key, index):
        if isinstance(index, MultiIndex):
            setattr(group._v_attrs, '%s_variety' % key, 'multi')
            self._write_multi_index(group, key, index)
        elif isinstance(index, BlockIndex):
            setattr(group._v_attrs, '%s_variety' % key, 'block')
            self._write_block_index(group, key, index)
        elif isinstance(index, IntIndex):
            setattr(group._v_attrs, '%s_variety' % key, 'sparseint')
            self._write_sparse_intindex(group, key, index)
        else:
            setattr(group._v_attrs, '%s_variety' % key, 'regular')
            converted, kind, _ = _convert_index(index)
            self._write_array(group, key, converted)
            node = getattr(group, key)
            node._v_attrs.kind = kind
            node._v_attrs.name = index.name

            if isinstance(index, (DatetimeIndex, PeriodIndex)):
                node._v_attrs.index_class = _class_to_alias(type(index))

            if hasattr(index, 'freq'):
                node._v_attrs.freq = index.freq

            if hasattr(index, 'tz') and index.tz is not None:
                zone = lib.get_timezone(index.tz)
                if zone is None:
                    zone = lib.tot_seconds(index.tz.utcoffset())
                node._v_attrs.tz = zone
Esempio n. 4
0
    def _write_index(self, group, key, index):
        if isinstance(index, MultiIndex):
            setattr(group._v_attrs, '%s_variety' % key, 'multi')
            self._write_multi_index(group, key, index)
        elif isinstance(index, BlockIndex):
            setattr(group._v_attrs, '%s_variety' % key, 'block')
            self._write_block_index(group, key, index)
        elif isinstance(index, IntIndex):
            setattr(group._v_attrs, '%s_variety' % key, 'sparseint')
            self._write_sparse_intindex(group, key, index)
        else:
            setattr(group._v_attrs, '%s_variety' % key, 'regular')
            converted, kind, _ = _convert_index(index)
            self._write_array(group, key, converted)
            node = getattr(group, key)
            node._v_attrs.kind = kind
            node._v_attrs.name = index.name

            if isinstance(index, (DatetimeIndex, PeriodIndex)):
                node._v_attrs.index_class = _class_to_alias(type(index))

            if hasattr(index, 'freq'):
                node._v_attrs.freq = index.freq

            if hasattr(index, 'tz') and index.tz is not None:
                zone = lib.get_timezone(index.tz)
                if zone is None:
                    zone = lib.tot_seconds(index.tz.utcoffset())
                node._v_attrs.tz = zone
Esempio n. 5
0
    def _prep_index(self,obj,duplicates={},data_start=0):
        info = {}
        types = {}
        data = []
        for i in range(obj.index.nlevels):
            name = obj.index.names[i]
            if name == None:
                str_name = 'index_%d'%i
            else:
                str_name = str(name)
            if str_name in info:
                if str_name in duplicates:
                    duplicates[str_name] += 1
                else:
                    duplicates[str_name] = 1
                str_name = str_name + '_%d'%duplicates[str_name]
            
            if isinstance(obj.index, MultiIndex):
                values = obj.index.levels[i]
            else:
                values = obj.index.values
            converted, kind, type = _convert_index(values,position=data_start+i)
            
            info[str_name] = {'name_data':name}
            
            if hasattr(values, 'freq'):
                info[str_name]['freq'] = values.freq

            if hasattr(values, 'tz') and values.tz is not None:
                zone = lib.get_timezone(values.tz)
                if zone is None:
                    zone = lib.tot_seconds(values.tz.utcoffset())
                info[str_name]['tz'] = zone      
                  
            info[str_name]['kind'] = kind
            info[str_name]['isIndex'] = True
            info[str_name]['position'] = i
            types[str_name] = type
            data.append(converted)
        
        return info,types,data,duplicates,i+1
Esempio n. 6
0
 def _infer(a, b):
     tz = a.tzinfo
     if b and b.tzinfo:
         assert (lib.get_timezone(tz) == lib.get_timezone(b.tzinfo))
     return tz
Esempio n. 7
0
 def _infer(a, b):
     tz = a.tzinfo
     if b and b.tzinfo:
         assert(lib.get_timezone(tz) == lib.get_timezone(b.tzinfo))
     return tz