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

sample doesn't preserve original object type #3456

Closed
MarcoGorelli opened this issue Jul 2, 2024 · 0 comments · Fixed by #3452
Closed

sample doesn't preserve original object type #3456

MarcoGorelli opened this issue Jul 2, 2024 · 0 comments · Fixed by #3452
Labels

Comments

@MarcoGorelli
Copy link
Contributor

What happened?

import polars as pl
import pandas as pd
import altair as alt

df_pd = pd.DataFrame({'a': [1,2,3]})
print(alt.sample(df_pd, n=2))
df_pl = pl.DataFrame({'a': [1,2,3]})
print(alt.sample(df_pl, n=2))

This outputs (exact values differ between runs due to the nature of sample, but the points is - Polars.DataFrame gets transformed to PyArrow)

   a
0  1
1  2
pyarrow.Table
a: int64
----
a: [[1,2]]

What would you like to happen instead?

The docs for alt.sample say

Reduce the size of the data model by sampling without replacement.

so I'd have expected the input library to be preserved, and to get something like:

   a
1  1
2  2
shape: (2, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 1   │
│ 2   │
└─────┘

Which version of Altair are you using?

5.3.0

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