How to use the arctic.date.mktz function in arctic

To help you get started, we’ve selected a few arctic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github man-group / arctic / tests / unit / tickstore / test_toplevel.py View on Github external
                          (dt(2009, 12, 31, 21, 10, tzinfo=mktz('America/New_York')), dt(2010, 12, 31, tzinfo=mktz('America/New_York'))),
                          (dt(2009, 12, 31, tzinfo=mktz('America/New_York')), dt(2010, 12, 31, tzinfo=mktz('America/New_York'))),
                          (dt(2009, 12, 31, 21, 10, tzinfo=mktz('America/New_York')), dt(2010, 12, 31, 9, 21, tzinfo=mktz('America/New_York')))
                          ])
def test_raise_error_add_library_is_called_with_a_date_range_not_on_day_boundaries(start, end):
    with pytest.raises(AssertionError) as e:
        self = create_autospec(TopLevelTickStore, _arctic_lib=MagicMock(), _collection=MagicMock())
        self._get_library_metadata.return_value = []
        TopLevelTickStore.add(self, DateRange(start=start, end=end), "blah")
    assert "Date range should fall on UTC day boundaries" in str(e.value)
github man-group / arctic / tests / unit / date / test_datetime_to_ms_roundtrip.py View on Github external
def test_datetime_roundtrip_est_tz():
    pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz('EST'))
    pdt2 = ms_to_datetime(datetime_to_ms(pdt))
    assert pdt2.replace(tzinfo=mktz()) == pdt

    pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz('EST'))
    pdt2 = ms_to_datetime(datetime_to_ms(pdt))
    assert pdt2.replace(tzinfo=mktz()) == pdt
github man-group / arctic / tests / integration / tickstore / test_ts_delete.py View on Github external
'index': dt(2013, 1, 1, tzinfo=mktz('Europe/London'))
               },
              {'a': 3.,
               'b': 4.,
               'index': dt(2013, 2, 1, tzinfo=mktz('Europe/London'))
               },
              ]
    tickstore_lib._chunk_size = 1
    tickstore_lib.write('SYM', DUMMY_DATA)

    # Delete with a date-range
    deleted = tickstore_lib.delete(
        'SYM',
        DateRange(
            dt(2013, 1, 1, tzinfo=mktz('Europe/London')),
            dt(2013, 2, 1, tzinfo=mktz('Europe/London')),
            CLOSED_OPEN
        )
    )
    assert deleted.deleted_count == 1
    df = tickstore_lib.read('SYM', columns=None)
    assert np.allclose(df['b'].values, np.array([4.]))
github man-group / arctic / tests / integration / pluggable / test_pandas_store.py View on Github external
def test_daterange_fails_with_timezone_start(generic_version_store):
    df = read_csv(StringIO("""2015-08-10 00:00:00,200005,1.0
                              2015-08-11 00:00:00,200016,3.0"""), parse_dates=[0],
                  names=['date', 'security_id', 'value']).set_index(['date', 'security_id'])
    generic_version_store.write('MYARR', df)
    with pytest.raises(ValueError):
        generic_version_store.read('MYARR', date_range=DateRange(start=dt(2015, 1, 1, tzinfo=mktz())))
github man-group / arctic / tests / unit / date / test_util.py View on Github external
@patch("arctic.date._util.mktz", lambda zone="Asia/Shanghai": mktz(zone))
def test_utc_dt_to_local_dt():
github man-group / arctic / tests / integration / tickstore / test_ts_read.py View on Github external
def test_read_chunk_boundaries(tickstore_lib):
    SYM1_DATA = [
                  {'a': 1.,
                   'b': 2.,
                   'index': dt(2013, 6, 1, 12, 00, tzinfo=mktz('UTC'))
                   },
                   {'a': 3.,
                   'b': 4.,
                   'index': dt(2013, 6, 1, 13, 00, tzinfo=mktz('UTC'))
                   },
                 # Chunk boundary here
                   {'a': 5.,
                   'b': 6.,
                   'index': dt(2013, 6, 1, 14, 00, tzinfo=mktz('UTC'))
                   }
                  ]
    SYM2_DATA = [
                  {'a': 7.,
                   'b': 8.,
                   'index': dt(2013, 6, 1, 12, 30, tzinfo=mktz('UTC'))
                   },
                   {'a': 9.,
                   'b': 10.,
                   'index': dt(2013, 6, 1, 13, 30, tzinfo=mktz('UTC'))
                   },
github man-group / arctic / arctic / tickstore / toplevel.py View on Github external
def _get_library_metadata(self, date_range):
        """
        Retrieve the libraries for the given date range, the assumption is that the date ranges do not overlap and
        they are CLOSED_CLOSED.

        At the moment the date range is mandatory
        """
        if date_range is None:
            raise Exception("A date range must be provided")
        if not (date_range.start and date_range.end):
            raise Exception("The date range {0} must contain a start and end date".format(date_range))

        start = date_range.start if date_range.start.tzinfo is not None else date_range.start.replace(tzinfo=mktz())
        end = date_range.end if date_range.end.tzinfo is not None else date_range.end.replace(tzinfo=mktz())
        query = {'$or': [{'start': {'$lte': start}, 'end': {'$gte': start}},
                         {'start': {'$gte': start}, 'end': {'$lte': end}},
                         {'start': {'$lte': end}, 'end': {'$gte': end}}]}

        cursor = self._collection.find(query,
                                       projection={'library_name': 1, 'start': 1, 'end': 1},
                                       sort=[('start', pymongo.ASCENDING)])

        results = []
        for res in cursor:
            start = res['start']
            if date_range.start.tzinfo is not None and start.tzinfo is None:
                start = start.replace(tzinfo=mktz("UTC")).astimezone(tz=date_range.start.tzinfo)

            end = res['end']
github man-group / arctic / arctic / tickstore / toplevel.py View on Github external
date_range: A date range provided on the assumption that it is CLOSED_CLOSED. If for example the underlying
        libraries were split by year, the start of the date range would be datetime.datetime(year, 1, 1) and the end
        would be datetime.datetime(year, 12, 31, 23, 59, 59, 999000). The date range must fall on UTC day boundaries,
        that is the start must be add midnight and the end must be 1 millisecond before midnight.

        library_name: The name of the underlying library. This must be the name of a valid Arctic library
        """
        # check that the library is valid
        try:
            self._arctic_lib.arctic[library_name]
        except Exception as e:
            logger.error("Could not load library")
            raise e
        assert date_range.start and date_range.end, "Date range should have start and end properties {}".format(date_range)
        start = date_range.start.astimezone(mktz('UTC')) if date_range.start.tzinfo is not None else date_range.start.replace(tzinfo=mktz('UTC'))
        end = date_range.end.astimezone(mktz('UTC')) if date_range.end.tzinfo is not None else date_range.end.replace(tzinfo=mktz('UTC'))
        assert start.time() == time.min and end.time() == end_time_min, "Date range should fall on UTC day boundaries {}".format(date_range)
        # check that the date range does not overlap
        library_metadata = self._get_library_metadata(date_range)
        if len(library_metadata) > 1 or (len(library_metadata) == 1 and library_metadata[0] != library_name):
            raise OverlappingDataException("""There are libraries that overlap with the date range:
library: {}
overlapping libraries: {}""".format(library_name, [l.library for l in library_metadata]))
        self._collection.update_one({'library_name': library_name},
                                    {'$set': {'start': start, 'end': end}}, upsert=True)
github man-group / arctic / arctic / tickstore / tickstore.py View on Github external
def _prepend_image(self, document, im, rtn_length, column_dtypes, column_set, columns):
        image = im[IMAGE]
        first_dt = im[IMAGE_TIME]
        if not first_dt.tzinfo:
            first_dt = first_dt.replace(tzinfo=mktz('UTC'))
        document[INDEX] = np.insert(document[INDEX], 0, np.uint64(datetime_to_ms(first_dt)))
        for field in image:
            if field == INDEX:
                continue
            if columns and field not in columns:
                continue
            if field not in document or document[field] is None:
                col_dtype = np.dtype(str if isinstance(image[field], string_types) else 'f8')
                document[field] = self._empty(rtn_length, dtype=col_dtype)
                column_dtypes[field] = col_dtype
                column_set.add(field)
            val = image[field]
            document[field] = np.insert(document[field], 0, document[field].dtype.type(val))
        # Now insert rows for fields in document that are not in the image
        for field in set(document).difference(set(image)):
            if field == INDEX: