Skip to content

Commit

Permalink
Merge pull request #282 from markfairbanks/plot
Browse files Browse the repository at this point in the history
Add `.plot`
  • Loading branch information
markfairbanks authored Oct 29, 2024
2 parents 917d9c7 + 54e23ef commit 0b4a5a6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* `pl.Null` is rexported as `tp.Null`
* `.rename()` `mapping` renamed to `_mapping` to avoid naming conflicts in
dplyr interface using kwargs
* Can now use `.plot` to access polars plotting

## v0.3.1

Expand Down
133 changes: 72 additions & 61 deletions tidypolars/tibble_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,34 @@ def filter(self, *args,
out = super().filter(exprs)

return out.pipe(from_polars)

def full_join(self, df, left_on = None, right_on = None, on = None, suffix: str = '_right'):
"""
Perform an full join
Parameters
----------
df : tibble
Lazy DataFrame to join with.
left_on : str, list
Join column(s) of the left DataFrame.
right_on : str, list
Join column(s) of the right DataFrame.
on: str, list
Join column(s) of both DataFrames. If set, `left_on` and `right_on` should be None.
suffix : str
Suffix to append to columns with a duplicate name.
Examples
--------
>>> df1.full_join(df2)
>>> df1.full_join(df2, on = 'x')
>>> df1.full_join(df2, left_on = 'left_x', right_on = 'x')
"""
if (left_on == None) & (right_on == None) & (on == None):
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 inner_join(self, df, left_on = None, right_on = None, on = None, suffix = '_right'):
"""
Expand Down Expand Up @@ -454,67 +482,6 @@ def mutate(self, *args,

return out.pipe(from_polars)

@property
def names(self):
"""
Get column names
Examples
--------
>>> df.names
"""
return super().columns

@property
def ncol(self):
"""
Get number of columns
Examples
--------
>>> df.ncol
"""
return super().shape[1]

@property
def nrow(self):
"""
Get number of rows
Examples
--------
>>> df.nrow
"""
return super().shape[0]

def full_join(self, df, left_on = None, right_on = None, on = None, suffix: str = '_right'):
"""
Perform an full join
Parameters
----------
df : tibble
Lazy DataFrame to join with.
left_on : str, list
Join column(s) of the left DataFrame.
right_on : str, list
Join column(s) of the right DataFrame.
on: str, list
Join column(s) of both DataFrames. If set, `left_on` and `right_on` should be None.
suffix : str
Suffix to append to columns with a duplicate name.
Examples
--------
>>> df1.full_join(df2)
>>> df1.full_join(df2, on = 'x')
>>> df1.full_join(df2, left_on = 'left_x', right_on = 'x')
"""
if (left_on == None) & (right_on == None) & (on == None):
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 pivot_longer(self,
cols = everything(),
names_to = "name",
Expand Down Expand Up @@ -948,6 +915,50 @@ def write_parquet(self,
**kwargs):
"""Write a data frame to a parquet"""
return super().write_parquet(file, compression = compression, use_pyarrow = use_pyarrow, **kwargs)

@property
def names(self):
"""
Get column names
Examples
--------
>>> df.names
"""
return super().columns

@property
def ncol(self):
"""
Get number of columns
Examples
--------
>>> df.ncol
"""
return super().shape[1]

@property
def nrow(self):
"""
Get number of rows
Examples
--------
>>> df.nrow
"""
return super().shape[0]

@property
def plot(self):
"""
Access to polars plotting
Examples
--------
>>> df.plot
"""
return super().plot

def desc(x):
"""Mark a column to order in descending"""
Expand Down

0 comments on commit 0b4a5a6

Please sign in to comment.