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

Support glimpse function #409

Open
chriscardillo opened this issue Mar 29, 2022 · 3 comments
Open

Support glimpse function #409

chriscardillo opened this issue Mar 29, 2022 · 3 comments
Labels
api:verb .help wanted Extra attention is needed

Comments

@chriscardillo
Copy link
Collaborator

chriscardillo commented Mar 29, 2022

Would be great to have dplyr's glimpse function implemented in siuba and loaded in with from siuba import *.

glimpse is really useful because pandas dataframes don't always print nicely.

@machow
Copy link
Owner

machow commented Mar 29, 2022

Agreed it would be nice! As I understand, glimpse (which is implemented in the pillar package) basically does the following:

  • transposes the normal table view, so each column shows up as a row
  • prints shape up top (e.g. Rows: 10, Columns: 2)
  • for each column, chooses the number of elements to show based on terminal width
    • e.g. one column might show 3, while another shows 15 (shorter representations)
  • has a generic format_glimpse for handling things like lists

Examples

Choosing n elements to show per column

glimpse(
  data.frame(
    x = c(paste0(rep("abc", 10), collapse = ""), rep("zzz", 9)),
    y = 1:10
  )
)

image

Different from straight transposing

Transposing a dataframe doesn't dynamically select number of columns (and jacks up the object representations; e.g. ints go to floats, etc..):

from siuba.data import mtcars
mtcars.head().T

image

(Note how this also jacks up representations)

Handles nested representations via a summary

image

To see how it handles each column:

nested = mtcars %>% nest(data = c(-cyl))
pillar:::format_glimpse_1(nested$data)
# [1] "[<tbl_df[7 x 10]>], [<tbl_df[11 x 10]>], [<tbl_df[14 x 10]>]"

@pwwang
Copy link

pwwang commented Apr 8, 2022

This is cool. Also want to implement it with datar.

pwwang added a commit to pwwang/datar that referenced this issue Apr 12, 2022
pwwang added a commit to pwwang/datar that referenced this issue Apr 12, 2022
* 🩹 Attach original `__module__` to `func_factory` registed functions

* ✨ Allow configuration file to save default options;
 💥Replace option `warn_builtin_names` with `imiport_names_conflict` (#73)

* 🐛 Register `base.factor()` and accept grouped data (#108)

* ✨ Support `base.glimpse()` (#107, machow/siuba#409)

* ✅ Add tests for `base.factor()` with grouped data

* 🔖 0.8.0

* 📝 Update CHANGELOG
@Holer90
Copy link

Holer90 commented Feb 27, 2023

I have implemented the glimpse function in pandas, opened a feature request and is in the process of submitting a pull request. Now we just need to hope someone has the time to review the pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:verb .help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants