Skip to content

Commit

Permalink
Changed encoded float::Inf as null in json (jorgecarleitao#1427)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSchneider authored and ritchie46 committed Mar 29, 2023
1 parent 78d0e4b commit 05cf5ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
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

0 comments on commit 05cf5ec

Please sign in to comment.