Skip to content

Commit

Permalink
.to to .as
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Sep 23, 2024
1 parent 3ea0028 commit 4283335
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tests/test_tibble.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_pull():
"""Can use pull"""
df = tp.tibble({'x': _repeat(1, 3), 'y': _repeat(2, 3)})
actual = df.pull('x')
expected = df.to_polars().get_column('x')
expected = df.as_polars().get_column('x')
assert actual.equals(expected), "pull failed"

def test_relocate_before():
Expand Down Expand Up @@ -432,10 +432,10 @@ def test_to_dict():
df = tp.tibble({'x': range(3), 'y': range(3)})
assert type(df.to_dict()) == dict

def test_to_polars():
def test_as_polars():
"""Can convert to a polars DataFrame"""
df = tp.tibble({'x': range(3), 'y': range(3), 'z': range(3)})
assert isinstance(df.to_polars(), pl.DataFrame), "to_polars failed"
assert isinstance(df.as_polars(), pl.DataFrame), "as_polars failed"

def test_unite():
"""Can unite columns"""
Expand Down
22 changes: 11 additions & 11 deletions tidypolars/tibble_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, _data = None, **kwargs):

def __repr__(self):
"""Printing method"""
df = self.to_polars()
df = self.as_polars()
return df.__str__()

def _repr_html_(self):
Expand All @@ -46,7 +46,7 @@ def _repr_html_(self):
* POLARS_FMT_MAX_ROWS: set the number of rows
"""
df = self.to_polars()
df = self.as_polars()
return df._repr_html_()

def __copy__(self):
Expand All @@ -58,7 +58,7 @@ def __copy__(self):

def __str__(self):
"""Printing method"""
df = self.to_polars()
df = self.as_polars()
return df.__str__()

def __getattribute__(self, attr):
Expand All @@ -75,7 +75,7 @@ def __dir__(self):
'pull', 'relocate', 'rename', 'replace_null', 'select',
'separate', 'set_names',
'slice', 'slice_head', 'slice_tail', 'summarize', 'tail',
'to_pandas', 'to_polars', 'write_csv', 'write_parquet'
'to_pandas', 'as_polars', 'write_csv', 'write_parquet'
]
return _tidypolars_methods

Expand Down Expand Up @@ -117,7 +117,7 @@ def bind_cols(self, *args):
>>> df1.bind_cols(df2)
"""
frames = _as_list(args)
out = self.to_polars()
out = self.as_polars()
for frame in frames:
out = out.hstack(frame)
return out.pipe(from_polars)
Expand Down Expand Up @@ -237,8 +237,8 @@ def drop_null(self, *args):

def equals(self, other, null_equal = True):
"""Check if two tibbles are equal"""
df = self.to_polars()
other = other.to_polars()
df = self.as_polars()
other = other.as_polars()
return df.equals(other, null_equal = null_equal)

def head(self, n = 5, *, _by = None):
Expand Down Expand Up @@ -397,7 +397,7 @@ def mutate(self, *args,
"""
exprs = _as_list(args) + _kwargs_as_exprs(kwargs)

out = self.to_polars()
out = self.as_polars()

if _uses_by(_by):
out = out.group_by(_by).map_groups(lambda x: _mutate_cols(x, exprs))
Expand Down Expand Up @@ -697,7 +697,7 @@ def separate(self, sep_col, into, sep = '_', remove = True):
into_len = len(into) - 1
sep_df = (
self
.to_polars()
.as_polars()
.select(col(sep_col)
.str.split_exact(sep, into_len)
.alias("_seps")
Expand Down Expand Up @@ -891,13 +891,13 @@ def to_pandas(self):
"""
return super().to_pandas()

def to_polars(self):
def as_polars(self):
"""
Convert to a polars DataFrame
Examples
--------
>>> df.to_polars()
>>> df.as_polars()
"""
self = copy.copy(self)
self.__class__ = pl.DataFrame
Expand Down

0 comments on commit 4283335

Please sign in to comment.