Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Changed encoded float::Inf as null in json #1427

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ The crate comes with additional submodules to aid with testing, to ensure you ha
git clone --recurse-submodules https://github.com/jorgecarleitao/arrow2
```

## Checks

PRs will run the following checks:

```bash
cargo fmt --all -- --check
cargo clippy --all --features=full --tests -- -D warnings
```

## Testing

The simplest way to test the crate is to run
Expand Down
2 changes: 1 addition & 1 deletion src/io/json/write/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
array.iter(),
|x, buf| {
if let Some(x) = x {
if T::is_nan(*x) {
if T::is_nan(*x) || T::is_infinite(*x) {
buf.extend(b"null")
} else {
lexical_to_bytes_mut(*x, buf)
Expand Down
24 changes: 20 additions & 4 deletions tests/it/io/json/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,34 @@ fn int32() -> Result<()> {

#[test]
fn f32() -> Result<()> {
let array = Float32Array::from([Some(1.5), Some(2.5), Some(f32::NAN), None, Some(5.5)]);
let array = Float32Array::from([
Some(1.5),
Some(2.5),
Some(f32::NAN),
Some(f32::INFINITY),
Some(f32::NEG_INFINITY),
None,
Some(5.5),
]);

let expected = r#"[1.5,2.5,null,null,5.5]"#;
let expected = r#"[1.5,2.5,null,null,null,null,5.5]"#;

test!(array, expected)
}

#[test]
fn f64() -> Result<()> {
let array = Float64Array::from([Some(1.5), Some(2.5), Some(f64::NAN), None, Some(5.5)]);
let array = Float64Array::from([
Some(1.5),
Some(2.5),
Some(f64::NAN),
Some(f64::INFINITY),
Some(f64::NEG_INFINITY),
None,
Some(5.5),
]);

let expected = r#"[1.5,2.5,null,null,5.5]"#;
let expected = r#"[1.5,2.5,null,null,null,null,5.5]"#;

test!(array, expected)
}
Expand Down