Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Utf8View <=> boolean casting #6713

Open
Omega359 opened this issue Nov 11, 2024 · 1 comment
Open

Support Utf8View <=> boolean casting #6713

Omega359 opened this issue Nov 11, 2024 · 1 comment
Assignees
Labels
enhancement Any new improvement worthy of a entry in the changelog

Comments

@Omega359
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

While working on upgrading to DF 43 I discovered that casting support for utf8view <-> bool has not been implemented

Describe the solution you'd like

Support casting to/from bool with utf8view's

Additional context

arrow-cast/src/cast/mod.rs

 #[test]
    fn test_cast_utf8view_to_bool() {
        let strings = StringViewArray::from(vec!["true", "false", "invalid", " Y ", ""]);
        let casted = cast(&strings, &DataType::Boolean).unwrap();
        let expected = BooleanArray::from(vec![Some(true), Some(false), None, Some(true), None]);
        assert_eq!(*as_boolean_array(&casted), expected);
    }

    #[test]
    fn test_cast_with_options_utf8view_to_bool() {
        let strings = StringViewArray::from(vec!["true", "false", "invalid", " Y ", ""]);
        let casted = cast_with_options(
            &strings,
            &DataType::Boolean,
            &CastOptions {
                safe: false,
                format_options: FormatOptions::default(),
            },
        );
        match casted {
            Ok(_) => panic!("expected error"),
            Err(e) => {
                assert!(e
                    .to_string()
                    .contains("Cast error: Cannot cast value 'invalid' to value of Boolean type"))
            }
        }
    }

    #[test]
    fn test_cast_bool_to_utf8view() {
        let array = BooleanArray::from(vec![Some(true), Some(false), None]);
        let b = cast(&array, &DataType::Utf8View).unwrap();
        let c = b.as_any().downcast_ref::<StringViewArray>().unwrap();
        assert_eq!("true", c.value(0));
        assert_eq!("false", c.value(1));
        assert!(!c.is_valid(2));
    }
@Omega359 Omega359 added the enhancement Any new improvement worthy of a entry in the changelog label Nov 11, 2024
@tlm365
Copy link
Contributor

tlm365 commented Nov 11, 2024

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

No branches or pull requests

2 participants