def __init__(self, data=None, start=None, end=None, periods=None, freq='D', index=None): if index is None: if not data is None: if isinstance(data, MIArray): data = data.aslist() self.data = data if isinstance(data[0], datetime.datetime): self._index = MIDateTimeIndex(miutil.jdate(data)) else: self._index = MIDateTimeIndex(data) else: if start is None: self._index = MIDateTimeIndex(periods, end, freq) elif end is None: self._index = MIDateTimeIndex(start, periods, freq) else: self._index = MIDateTimeIndex(start, end, freq) self.data = miutil.pydate(list(self._index.getDateValues())) else: self._index = index self.data = miutil.pydate(list(self._index.getDateValues()))
class DateTimeIndex(Index): def __init__(self, data=None, start=None, end=None, periods=None, freq='D', index=None): if index is None: if not data is None: if isinstance(data, MIArray): data = data.aslist() self.data = data if isinstance(data[0], datetime.datetime): self._index = MIDateTimeIndex(miutil.jdate(data)) else: self._index = MIDateTimeIndex(data) else: if start is None: self._index = MIDateTimeIndex(periods, end, freq) elif end is None: self._index = MIDateTimeIndex(start, periods, freq) else: self._index = MIDateTimeIndex(start, end, freq) self.data = miutil.pydate(list(self._index.getDateValues())) else: self._index = index self.data = miutil.pydate(list(self._index.getDateValues())) def index(self, v): ''' Get index of a value. :param v: (*datetime or string*) Date time value :returns: (*int*) Value index ''' if isinstance(v, datetime.datetime): v = miutil.jdatetime(v) else: v = miutil.str2jdate(v) return self._index.indexOf(v) def get_loc(self, key, outkeys=False): ''' Get integer location, slice or boolean mask for requested label. :param key: (*string or list*) Label. :param outkeys: (*boolean*) If return location keys or not. :returns: int if unique index, slice if monotonic index, else mask. ''' if isinstance(key, datetime.datetime): key = miutil.jdatetime(key) elif isinstance(key, (list, tuple)) and isinstance(key[0], datetime.datetime): key = miutil.jdatetime(key) r = self._index.getIndices(key) if outkeys: return list(r[0]), list(r[1]) else: return list(r[0])
class DateTimeIndex(Index): def __init__(self, data=None, start=None, end=None, periods=None, freq='D', index=None): if index is None: if not data is None: if isinstance(data, MIArray): data = data.aslist() self.data = data if isinstance(data[0], datetime.datetime): self._index = MIDateTimeIndex(miutil.jdate(data)) else: self._index = MIDateTimeIndex(data) else: if start is None: self._index = MIDateTimeIndex(periods, end, freq) elif end is None: self._index = MIDateTimeIndex(start, periods, freq) else: self._index = MIDateTimeIndex(start, end, freq) self.data = miutil.pydate(list(self._index.getDateValues())) else: self._index = index self.data = miutil.pydate(list(self._index.getDateValues())) def index(self, v): ''' Get index of a value. :param v: (*datetime or string*) Date time value :returns: (*int*) Value index ''' if isinstance(v, datetime.datetime): v = miutil.jdatetime(v) else: v = miutil.str2jdate(v) return self._index.indexOf(v) def get_loc(self, key, outkeys=False): ''' Get integer location, slice or boolean mask for requested label. :param key: (*string or list*) Label. :param outkeys: (*boolean*) If return location keys or not. :returns: int if unique index, slice if monotonic index, else mask. ''' if isinstance(key, datetime.datetime): key = miutil.jdatetime(key) elif isinstance(key, (list, tuple, MIArray)) and isinstance(key[0], datetime.datetime): key = miutil.jdatetime(key) r = self._index.getIndices(key) if outkeys: return list(r[0]), list(r[1]) else: return list(r[0])
class DateTimeIndex(Index): def __init__(self, data=None, start=None, end=None, periods=None, freq='D', index=None): if index is None: if not data is None: if isinstance(data, NDArray): data = data.aslist() self.data = data if isinstance(data[0], datetime.datetime): self._index = MIDateTimeIndex(miutil.jdate(data)) else: self._index = MIDateTimeIndex(data) else: if start is None: self._index = MIDateTimeIndex(periods, end, freq) elif end is None: self._index = MIDateTimeIndex(start, periods, freq) else: self._index = MIDateTimeIndex(start, end, freq) self.data = miutil.pydate(list(self._index.getDateValues())) else: self._index = index self.data = miutil.pydate(list(self._index.getDateValues())) def index(self, v): ''' Get index of a value. :param v: (*datetime or string*) Date time value :returns: (*int*) Value index ''' if isinstance(v, datetime.datetime): v = miutil.jdatetime(v) else: v = miutil.str2jdate(v) return self._index.indexOf(v) def get_loc(self, key, outkeys=False): ''' Get integer location, slice or boolean mask for requested label. :param key: (*string or list*) Label. :param outkeys: (*boolean*) If return location keys or not. :returns: int if unique index, slice if monotonic index, else mask. ''' if isinstance(key, NDArray) and key.dtype.kind == 'b': r = self._index.filterIndices(key.asarray()) return list(r) elif isinstance(key, datetime.datetime): key = miutil.jdatetime(key) elif isinstance(key, (list, tuple, NDArray)) and isinstance(key[0], datetime.datetime): key = miutil.jdatetime(key) r = self._index.getIndices(key) if outkeys: return list(r[0]), list(r[1]) else: return list(r[0]) @property def year(self): ''' Get year index. ''' r = self._index.getYear() return Index(index=r) @property def month(self): ''' Get month index. ''' r = self._index.getMonth() return Index(index=r) @property def day(self): ''' Get day index. ''' r = self._index.getDay() return Index(index=r) @property def hour(self): ''' Get hour index. ''' r = self._index.getHOur() return Index(index=r) @property def minute(self): ''' Get minute index. ''' r = self._index.getMinute() return Index(index=r) @property def second(self): ''' Get second index. ''' r = self._index.getSecond() return Index(index=r)