dotnet/machinelearning · error · ArgumentException

Strings.CannotResizeDown

Error message

Strings.CannotResizeDown

What it means

Not-implemented sentinel in VBufferDataFrameColumn.Resize: like other DataFrameColumn implementations, Resize can only extend the column (appending default VBuffer<T> entries). Requesting a length shorter than the current Length would discard rows, so the guard throws Strings.CannotResizeDown rather than truncating silently.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/VBufferDataFrameColumn.cs:62

        public VBufferDataFrameColumn(string name, IEnumerable<VBuffer<T>> values) : base(name, 0, typeof(VBuffer<T>))
        {
            values = values ?? throw new ArgumentNullException(nameof(values));
            if (_vBuffers.Count == 0)
            {
                _vBuffers.Add(new List<VBuffer<T>>());
            }
            foreach (var value in values)
            {
                Append(value);
            }
        }

        public override long NullCount => 0;

        protected internal override void Resize(long length)
        {
            if (length < Length)
                throw new ArgumentException(Strings.CannotResizeDown, nameof(length));

            for (long i = Length; i < length; i++)
            {
                Append(default);
            }
        }

        public void Append(VBuffer<T> value)
        {
            List<VBuffer<T>> lastBuffer = _vBuffers[_vBuffers.Count - 1];
            if (lastBuffer.Count == MaxCapacity)
            {
                lastBuffer = new List<VBuffer<T>>();
                _vBuffers.Add(lastBuffer);
            }
            lastBuffer.Add(value);
            Length++;
        }

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Resize only to lengths >= column.Length
  2. Create a new VBufferDataFrameColumn<T> of the desired smaller size and copy the prefix rows
  3. Use Slice/take operations instead of truncating in place
  4. Track prior length and call Resize(newLength - currentLength) semantics correctly

Example fix

// before
if (newLength < column.Length) column.Resize(newLength);
// after
var trimmed = new VBufferDataFrameColumn<T>(column.Name);
for (long i = 0; i < newLength; i++) trimmed.Append(column[i]);
Defensive patterns

Strategy: validation

Validate before calling

if (newLength < column.Length) throw new ArgumentException("Cannot shrink VBufferDataFrameColumn via Resize");

Type guard

bool CanResizeTo(long current, long target) => target >= current;

Try / catch

try { column.Resize(newLength); } catch (ArgumentException) { /* rebuild smaller column */ }

Prevention

When it happens

Trigger: Calling Resize(length) with length < column.Length; truncating a VBuffer column directly.

Common situations: Reusing a pooled column across batches where the new batch is smaller; resizing to match a shorter DataFrame.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/426912355eee0c54. Report an issue: GitHub.