Skip to content

[Rust] Nulls should be rendered as "" rather than default value when pretty printing arrays #26177

@asfimport

Description

@asfimport

Null values should be printed as "" when pretty printing. However, as of now, null values in primative arrays are rendered as the type's default value .

For example:

    fn test_pretty_format_batches() -> Result<()> {
        // define a schema.
        let schema = Arc::new(Schema::new(vec![
            Field::new("a", DataType::Utf8, true),
            Field::new("b", DataType::Int32, true),
        ]));

        // define data.
        let batch = RecordBatch::try_new(
            schema,
            vec![
                Arc::new(array::StringArray::from(vec![Some("a"), Some("b"), None, Some("d")])),
                Arc::new(array::Int32Array::from(vec![Some(1), None, Some(10), Some(100)])),
            ],
        )?;

        println!(pretty_format_batches(&[batch])?);

        Ok(())
    }

Outputs:

+---+-----+
| a | b   |
+---+-----+
| a | 1   |
| b | 0   |
|   | 10  |
| d | 100 |
+---+-----+

The second row of b should be '', not 0. The third row of a should also be '', which I think t is by accident

Thanks to @jhorstmann horstmann for pointing this out on #8331 (comment)

Reporter: Andrew Lamb / @alamb
Assignee: Andrew Lamb / @alamb

PRs and other links:

Note: This issue was originally created as ARROW-10169. Please see the migration documentation for further details.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions