﻿# Integer narrowing in feature pipelines: reject overflow before labels wrap

Integer narrowing in feature pipelines: reject overflow before labels wrap. A practical data-quality guide with failure mechanisms, validation steps, acceptance evidence and primary references.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/dq-integer-narrowing-label-overflow/
Language: en

A pipeline narrows an integer feature to reduce memory. Values outside the target range are truncated or rejected differently across readers, producing inconsistent training and evaluation inputs.

## The mechanism that changes the example

Storage optimization changes representable values. Safe casting, signedness and sentinel handling therefore belong to the data contract rather than being independent runtime tuning choices.



## Define the comparison boundary

Compare source range with the target type before constructing a narrow array. Signedness and any special sentinel values matter independently. A negative missing-value marker must not silently become a valid large category under an unsigned interpretation.

Use the selected Arrow cast safety policy explicitly and retain rejected values. An unsafe conversion is not a compression proof: it changes the accepted value domain. Test source bounds and values immediately outside the target domain instead of validating only common small examples.

Reopen the written artifact through the actual training reader and compare values and validity masks. A correct in-memory conversion can still be followed by an incompatible writer or reader. Future incremental partitions need the same range check; the maximum seen in an earlier sample is evidence about that sample, not a permanent source guarantee.

## A constructed test case

For a signed narrow target, include the largest accepted value and the next source value beyond it. The latter must not become another valid class or sentinel through wrapping; inspect the actual exported value and rejection disposition.

## A reproducible validation procedure

Determine target bounds before conversion. Test values at each bound and just beyond it, including source sentinels. Require either exact round-trip equality or an explicit rejected-record report; never accept silent wrapping.

Include an unchanged control and a deliberately invalid case. Verify that the checker distinguishes them before testing the complete release.

Exercise the actual preparation path, including later serialization and reload. Limit retained diagnostic content to the evidence required for this comparison.

## Evidence needed for acceptance

Keep range statistics, cast settings and rejected row identities for the exact release input.

## Containment and recovery

Observed bounds in a sample do not guarantee that a future incremental partition will fit.

Quarantine an invalid release candidate or use an explicit partial-release rule. Preserve the last approved artifact and record corrections without silently rewriting historical inputs.

## Interpretation and references

Implementation references: [Arrow casting and safety options](https://arrow.apache.org/docs/python/generated/pyarrow.compute.cast.html); [Arrow compute functions](https://arrow.apache.org/docs/python/compute.html).

This is a proposed engineering validation, not an executed Retrivium benchmark. Documentation specifies interfaces; dataset acceptance needs its own evidence and must be repeated after relevant dependency changes.

## Related reading

Continue with [LightGBM categorical codes: negative IDs mean missing values, not another category](/journal/fg2-lightgbm-categorical-integer-codes-negative-missing-schema/); [Apache Arrow: nulls, empty lists and nested training features](/journal/data-guide-arrow-nullable-feature-contract/). These guides supply adjacent context; the decision in this article remains the specific example-preservation check above.
