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

Using NULL and NA in pl$DataFrame() shouldn't be identical #1218

Open
etiennebacher opened this issue Sep 2, 2024 · 1 comment
Open

Using NULL and NA in pl$DataFrame() shouldn't be identical #1218

etiennebacher opened this issue Sep 2, 2024 · 1 comment

Comments

@etiennebacher
Copy link
Collaborator

etiennebacher commented Sep 2, 2024

I don't know if pl$DataFrame(x = NULL) should generate a DataFrame of height 1 to begin with.

length(NULL)
#> [1] 0
arrow::arrow_table(x = NULL)
#> Table
#> 0 rows x 1 columns
#> $x <null>

Created on 2024-09-02 with reprex v2.1.1

In my opinion, since NULL is zero length, it makes more sense to generate a DataFrame with zero height like arrow::arrow_table() does.

(On next branch, this pattern generates a DataFrame with height 0.)

neopolars::pl$DataFrame(x = NULL)
#> shape: (0, 1)
#> ┌──────┐
#> │ x    │
#> │ ---  │
#> │ null │
#> ╞══════╡
#> └──────┘

Created on 2024-09-02 with reprex v2.1.1

Originally posted by @eitsupi in #1216 (comment)

@eitsupi
Copy link
Collaborator

eitsupi commented Sep 3, 2024

In looking into this, I found that arrow and nanoarrow map the null type of Apache Arrow to vctrs::unspecified.
This seems reasonable to me, and I have achieved the same conversion in the next branch.

arrow::arrow_table(x = vctrs::unspecified(10))
#> Table
#> 10 rows x 1 columns
#> $x <null>
#>
#> See $metadata for additional Schema metadata
arrow::arrow_table(x = vctrs::unspecified(10)) |> tibble::as_tibble()
#> # A tibble: 10 × 1
#>        x
#>    <???>
#>  1     .
#>  2     .
#>  3     .
#>  4     .
#>  5     .
#>  6     .
#>  7     .
#>  8     .
#>  9     .
#> 10     .
neopolars::pl$DataFrame(x = vctrs::unspecified(10))
#> shape: (10, 1)
#> ┌──────┐
#> │ x    │
#> │ ---  │
#> │ null │
#> ╞══════╡
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> │ null │
#> └──────┘
neopolars::pl$DataFrame(x = vctrs::unspecified(10)) |> tibble::as_tibble()
#> # A tibble: 10 × 1
#>        x
#>    <???>
#>  1     .
#>  2     .
#>  3     .
#>  4     .
#>  5     .
#>  6     .
#>  7     .
#>  8     .
#>  9     .
#> 10     .

Created on 2024-09-03 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants