microsoft/qlib · error · ValueError

Expected pd.Timestamp for `cur_time`, got '{cur_time}'. Advi

Error message

Expected pd.Timestamp for `cur_time`, got '{cur_time}'. Advices: you can't query PIT data directly(e.g. '$$roewa_q'), you must use `P` operator to convert data to each day (e.g. 'P($$roewa_q)')

What it means

`LocalPITProvider.period_feature` requires `cur_time` to be a `pd.Timestamp`. Point-in-time financial data (fields starting with `$$`, e.g. `$$roewa_q`) is only meaningful 'as of' a query date; qlib supplies that date through the `P(...)` operator, which walks the calendar and passes a Timestamp per day. Calling the PIT provider with a raw index, string, or None (i.e. bypassing P) raises this ValueError.

Source

Thrown at qlib/data/data.py:750

    def __init__(self, remote=False, backend={}):
        super().__init__()
        self.remote = remote
        self.backend = backend

    def feature(self, instrument, field, start_index, end_index, freq):
        # validate
        field = str(field)[1:]
        instrument = code_to_fname(instrument)
        return self.backend_obj(instrument=instrument, field=field, freq=freq)[start_index : end_index + 1]


class LocalPITProvider(PITProvider):
    # TODO: Add PIT backend file storage
    # NOTE: This class is not multi-threading-safe!!!!

    def period_feature(self, instrument, field, start_index, end_index, cur_time, period=None):
        if not isinstance(cur_time, pd.Timestamp):
            raise ValueError(
                f"Expected pd.Timestamp for `cur_time`, got '{cur_time}'. Advices: you can't query PIT data directly(e.g. '$$roewa_q'), you must use `P` operator to convert data to each day (e.g. 'P($$roewa_q)')"
            )

        assert end_index <= 0  # PIT don't support querying future data

        DATA_RECORDS = [
            ("date", C.pit_record_type["date"]),
            ("period", C.pit_record_type["period"]),
            ("value", C.pit_record_type["value"]),
            ("_next", C.pit_record_type["index"]),
        ]
        VALUE_DTYPE = C.pit_record_type["value"]

        field = str(field).lower()[2:]
        instrument = code_to_fname(instrument)

        # {For acceleration
        # start_index, end_index, cur_index = kwargs["info"]

View on GitHub (pinned to 79633dd950)

Solutions

  1. Wrap the PIT field: `D.features(insts, ['P($$roewa_q)'])`.
  2. For multiple fields, wrap each: `['P($$roewa_q)', 'P($$assets_a)']`.

Example fix

# before
df = D.features(insts, ['$$roewa_q'], start_time='2020-01-01', end_time='2020-12-31')

# after
df = D.features(insts, ['P($$roewa_q)'], start_time='2020-01-01', end_time='2020-12-31')
Defensive patterns

Strategy: validation

Validate before calling

PIT_FIELDS = {'$$roewa_q', '$$assets_a'}  # example

def fields_are_pit_safe(fields):
    # every $$ (PIT) field must be wrapped in P(...)
    return all(not f.startswith('$$') for f in map(str.strip, fields))

Type guard

def is_pit_field(f: str) -> bool:
    return str(f).startswith('$$') and not str(f).startswith('P(')

Prevention

When it happens

Trigger: Using a PIT field directly in `D.features`: `D.features(insts, ['$$roewa_q'])`, or `$$field` inside another expression without wrapping it in `P(...)`.

Common situations: Users exploring quarterly/annual financial data who assume `$$` fields behave like `$` price fields. The error message itself is the documented fix: wrap in P.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/a5f0c6468f6f9302. Report an issue: GitHub.