Skip to content

test: pin TFTInstanceSplitter observed_value_field=None branch (#3296 item 3) - #3299

Open
jbbqqf wants to merge 1 commit into
awslabs:devfrom
jbbqqf:feat/3296a-tft-splitter-test
Open

test: pin TFTInstanceSplitter observed_value_field=None branch (#3296 item 3)#3299
jbbqqf wants to merge 1 commit into
awslabs:devfrom
jbbqqf:feat/3296a-tft-splitter-test

Conversation

@jbbqqf

@jbbqqf jbbqqf commented May 9, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: refs #3296 (item 3)

Description of changes:

Summary

Add a regression test pinning the observed_value_field=None branch of TFTInstanceSplitter, introduced by #3259 but not covered by the test suite.

Context

#3296 enumerates regression-test gaps left by recent merged PRs. Item 3:

#3259observed_value_field: Optional[str]: no test passing None through TFTInstanceSplitter on a toy dataset. The happy path with the default field name is covered; the new None branch isn't.

grep -rn TFTInstanceSplitter test/ confirms there were zero direct tests for this class. Without a test, a future refactor could regress the None branch silently — the flatmap_transform method only branches on if self.observed_value_field is not None: (src/gluonts/transform/split.py:533-534), and the integration tests in test/torch/model/test_estimators.py only exercise the default field-name path.

Changes

  • test/transform/test_transform.py: add test_TFTInstanceSplitter_observed_value_field_optional, a pytest.parametrize over [None, FieldName.OBSERVED_VALUES] that:
    • Runs the splitter end-to-end on a small data dict using TestSplitSampler.
    • Asserts past_target always has the configured past_length.
    • Asserts the None branch emits neither observed_values nor past_observed_values, and does not require the entry to carry an observed-values array.
    • Asserts the default-like branch emits past_observed_values with the right length.

A short docstring on the test cites #3259 and #3296 so a reviewer reading the test cold sees the regression it guards.

Reproduce BEFORE/AFTER yourself (copy-paste)

git clone https://github.com/awslabs/gluonts.git /tmp/repro && cd /tmp/repro
python3.11 -m venv .venv && source .venv/bin/activate
pip install -e . pytest

# --- BEFORE (origin/dev) ---
git checkout origin/dev
pytest test/transform/test_transform.py -q -k TFTInstanceSplitter
# Expected: 0 tests collected — there is no TFTInstanceSplitter test on dev.

# --- AFTER (this PR) ---
git fetch https://github.com/jbbqqf/gluonts.git feat/3296a-tft-splitter-test
git checkout FETCH_HEAD
pytest test/transform/test_transform.py -q -k TFTInstanceSplitter
# Expected: 2 passed — both branches pinned.

What I ran locally

  • pytest test/transform/test_transform.py -q252 passed, 4 skipped on the branch (was 250 + 4 on dev; +2 from this PR).
  • pytest test/transform/test_transform.py -q -k TFTInstanceSplitter2 passed.

Edge cases tested

# Scenario Input Expected Verified by
1 observed_value_field=None data dict without an observed-values array splitter returns one entry; no observed_values / past_observed_values keys test_TFTInstanceSplitter_observed_value_field_optional[None]
2 observed_value_field=FieldName.OBSERVED_VALUES data dict with observed_values mask splitter returns one entry with past_observed_values of length past_length test_TFTInstanceSplitter_observed_value_field_optional[observed_values]

Risk / blast radius

Test-only addition. Zero runtime impact.

Release note

NONE

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Please tag this pr with at least one of these labels to make our release process faster: BREAKING, new feature, bug fix, other change, dev setup


PR drafted with assistance from Claude Code. The reproducer block above was used during development and is the same one a reviewer can paste verbatim.

awslabs#3259 made `observed_value_field` optional in TFTInstanceSplitter but
did not add a test exercising the new None branch — the umbrella
follow-up awslabs#3296 (item 3) flags this as a regression-test gap.

Add a parametrized test covering both branches:
- `observed_value_field=None`: splitter must not look up an
  observed-values array on the entry, and output must contain neither
  `past_observed_values` nor `observed_values`.
- `observed_value_field=FieldName.OBSERVED_VALUES`: the existing
  default-like behaviour still emits `past_observed_values` of the
  configured length.

Refs awslabs#3296
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.

1 participant