Skip to content

Commit

Permalink
Merge pull request #284 from markfairbanks/glimpse
Browse files Browse the repository at this point in the history
Add `.glimpse()`
  • Loading branch information
markfairbanks authored Nov 2, 2024
2 parents e3c5e1a + af1ee72 commit 1b1db22
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v0.3.2 (in development)

#### New tibble methods

* `.glimpse()`

#### Functionality improvements

* `pl.Null` is rexported as `tp.Null`
Expand Down
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [`.drop()`](https://tidypolars.readthedocs.io/en/latest/autoapi/tidypolars/tibble/index.html#tidypolars.tibble_df.tibble.drop)
* [`.head()`](https://tidypolars.readthedocs.io/en/latest/autoapi/tidypolars/tibble/index.html#tidypolars.tibble_df.tibble.head)
* [`.filter()`](https://tidypolars.readthedocs.io/en/latest/autoapi/tidypolars/tibble/index.html#tidypolars.tibble_df.tibble.filter)
* [`.glimpse()`](https://tidypolars.readthedocs.io/en/latest/autoapi/tidypolars/tibble/index.html#tidypolars.tibble_df.tibble.glimpse)
* Joins
* [`.full_join()`](https://tidypolars.readthedocs.io/en/latest/autoapi/tidypolars/tibble/index.html#tidypolars.tibble_df.tibble.full_join)
* [`.inner_join()`](https://tidypolars.readthedocs.io/en/latest/autoapi/tidypolars/tibble/index.html#tidypolars.tibble_df.tibble.inner_join)
Expand Down
16 changes: 13 additions & 3 deletions tidypolars/tibble_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __dir__(self):
'arrange', 'as_dict', 'as_pandas', 'as_polars',
'bind_cols', 'bind_rows', 'colnames', 'clone', 'count',
'distinct', 'drop', 'drop_null', 'head', 'fill', 'filter',
'glimpse',
'inner_join', 'left_join', 'mutate', 'names', 'nrow', 'ncol',
'full_join', 'pivot_longer', 'pivot_wider',
'print',
Expand Down Expand Up @@ -289,9 +290,14 @@ def equals(self, other, null_equal = True):
other = other.as_polars()
return df.equals(other, null_equal = null_equal)

def head(self, n = 5, *, _by = None):
"""Alias for `.slice_head()`"""
return self.slice_head(n, _by = _by)
def glimpse(self):
"""
Return a dense preview of the DataFrame.
The formatting shows one line per column so that wide dataframes display cleanly.
Each line shows the column name, the data type, and the first few values.
"""
return self.as_polars().glimpse()

def fill(self, *args, direction = 'down', _by = None):
"""
Expand Down Expand Up @@ -394,6 +400,10 @@ def full_join(self, df, left_on = None, right_on = None, on = None, suffix: str
on = list(set(self.names) & set(df.names))
out = super().join(df, on, "full", left_on = left_on, right_on = right_on, suffix = suffix, coalesce = True)
return out.pipe(from_polars)

def head(self, n = 5, *, _by = None):
"""Alias for `.slice_head()`"""
return self.slice_head(n, _by = _by)

def inner_join(self, df, left_on = None, right_on = None, on = None, suffix = '_right'):
"""
Expand Down

0 comments on commit 1b1db22

Please sign in to comment.