Skip to content

can_cast_types reports string → negative-scale decimal as supported, but cast always errors #10792

Closed

Description

@neilconway

Describe the bug

See repro; the cast ought to work.

To Reproduce

use arrow_array::{ArrayRef, StringArray, Float64Array};
use arrow_cast::{can_cast_types, cast};
use arrow_schema::DataType;
use std::sync::Arc;

assert!(can_cast_types(&DataType::Utf8, &DataType::Decimal128(10, -2)));
let strings: ArrayRef = Arc::new(StringArray::from(vec!["100"]));
cast(&strings, &DataType::Decimal128(10, -2)).unwrap();
// Err: Invalid argument error: Cannot cast string to decimal with negative scale -2
// (also with CastOptions { safe: true })

let floats: ArrayRef = Arc::new(Float64Array::from(vec![100.0]));
cast(&floats, &DataType::Decimal128(10, -2)).unwrap(); // works

Expected behavior

No response

Additional context

No response

Activity

  1. added
    bug
    on Aug 21, 2026
  2. added theissue type on Aug 21, 2026
  3. neilconway commented on Aug 21, 2026

    @neilconway
    ContributorAuthor

    take

  4. Lstarsky0 commented on Aug 23, 2026

    @Lstarsky0
    Contributor

    The arm is cast/mod.rs:209-213 — Utf8View | Utf8 | LargeUtf8 to any Decimal* is an unconditional true. The rejection is at cast/decimal.rs:798.

    The float path you're contrasting with does handle negative scale: cast/mod.rs:375 branches on scale < 0 and divides by 10^-scale. The string path has no divide because parse_decimal has none, which is #10791. So the two ways to close this aren't equivalent — narrowing can_cast_types to scale >= 0 restores the contract but leaves string to negative-scale decimal unsupported, whereas making the cast work means #10791 lands first. Probably worth settling which one is wanted before someone starts, since #10791 is already taken.

    The same arm also over-reports for scale > MAX_SCALE:

    can_cast_types(Utf8, Decimal128(10, 40)) == true
    cast Utf8    -> Err "Cannot cast string to decimal greater than maximum scale 38"
    cast Float64 -> Err "scale 40 is greater than max 38"
    

    That one has only a single resolution, since no source type supports it. Same arm, so whatever lands here should probably cover both.

  5. added a commit that references this issue on Sep 1, 2026
    70219af
  6. added 3 commits that reference this issue on Sep 18, 2026
    f9eb4aa
    8bac2b6
    e9e1631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions