镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(data): accept datetime bounds in the PIT P operator - #2376

Open
Divyansh Barodiya (Divyansh151005) wants to merge 1 commit into
microsoft:mainfrom
Divyansh151005:fix/1551-pit-datetime-bounds
Open

Divyansh Barodiya (Divyansh151005) wants to merge 1 commit into
microsoft:mainfrom
Divyansh151005:fix/1551-pit-datetime-bounds

Conversation

@Divyansh151005

@Divyansh151005 Divyansh Barodiya (Divyansh151005) commented Oct 17, 2026 •

Copy link
Copy Markdown

Description

P now accepts the datetime bounds passed by LocalExpressionProvider when time2idx=False.

P._load_internal builds its result length with end_index - start_index + 1 and then walks integer calendar positions. With time2idx=True those bounds are calendar positions. With time2idx=False the provider passes the query datetimes through. Timestamp - Timestamp is a Timedelta, and Timedelta + 1 raises:

TypeError: unsupported operand type(s) for +: 'Timedelta' and 'int'

Datetime bounds are aligned with Cal.locate_index. That path returns a series indexed by the aligned trading days, so series.loc[start_time:end_time] in the provider still selects the requested range. Integer queries still return a RangeIndex. A future period reference is still rejected, and missing period data still returns an empty series.

Motivation and Context

Fixes #1551

P($$roewa_q) is the supported way to read a point-in-time feature on each trading day. time2idx=False is the expression-provider mode for datetime-indexed data, and P was the operator that crashed on those bounds.

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • If you are adding a new feature, test on your own test scripts.

test_all_pipeline.py trains a CSI300 LightGBM workflow and needs the market dataset. These tests stub the period feature and the calendar. They do not read PIT files or market data.

$ python -m pytest tests/ops/test_pit_operator.py -q --tb=line
....                                                                     [100%]
4 passed in 1.41s

flake8 on the changed Python files, with the ignore list from the developer guide, reported no issues. black -l 120 left the files unchanged.

Screenshots of Test Results (if appropriate):

  1. Pipeline test: not run. It needs the CSI300 dataset and a model fit.
  2. Your own tests: tests/ops/test_pit_operator.py, 4 passed.

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

time2idx=False passes query datetimes into P. Subtracting those timestamps produces a Timedelta, so building the result length raised TypeError. Datetime bounds are now aligned to the calendar, and that path keeps a datetime index.
@Divyansh151005

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set time2idx=False in expression_provider kwargs will cause unsupported operand type(s) for +: 'Timedelta' and 'int'

1 participant