From 0d93d6fce4c655cfe1c2623dcdb33aae4d1e4cc2 Mon Sep 17 00:00:00 2001 From: markfairbanks Date: Sat, 2 Nov 2024 08:32:06 -0600 Subject: [PATCH 1/3] Add `.glimpse()` --- docs/reference.md | 1 + tidypolars/tibble_df.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index a22f810..9b9a6f1 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -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) diff --git a/tidypolars/tibble_df.py b/tidypolars/tibble_df.py index 6305ad0..88ce369 100644 --- a/tidypolars/tibble_df.py +++ b/tidypolars/tibble_df.py @@ -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', @@ -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 super().glimpse() def fill(self, *args, direction = 'down', _by = None): """ @@ -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'): """ From 937ebb9235803ee1d91c1fc2388b39ef5cdc149b Mon Sep 17 00:00:00 2001 From: markfairbanks Date: Sat, 2 Nov 2024 08:34:05 -0600 Subject: [PATCH 2/3] Different logic --- tidypolars/tibble_df.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidypolars/tibble_df.py b/tidypolars/tibble_df.py index 88ce369..56008d1 100644 --- a/tidypolars/tibble_df.py +++ b/tidypolars/tibble_df.py @@ -297,7 +297,7 @@ def glimpse(self): 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 super().glimpse() + return self.as_polars().glimpse() def fill(self, *args, direction = 'down', _by = None): """ From af1ee725e6c7878824a2e192f5164a2b7a50e9d3 Mon Sep 17 00:00:00 2001 From: markfairbanks Date: Sat, 2 Nov 2024 08:35:19 -0600 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61114ae..cd7032f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## v0.3.2 (in development) +#### New tibble methods + +* `.glimpse()` + #### Functionality improvements * `pl.Null` is rexported as `tp.Null`