Skip to content

Commit

Permalink
All changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonStoykovQC committed Nov 28, 2023
1 parent 286bd22 commit 090d32b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/pydiverse/transform/core/table_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def alias(self, name=None) -> AbstractTableImpl:
def collect(self):
...

def collect_scalar(self):
...

def build_query(self):
...

Expand Down
6 changes: 6 additions & 0 deletions src/pydiverse/transform/core/verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def collect(tbl: AbstractTableImpl):
return tbl.collect()


@builtin_verb()
def collect_scalar(tbl: AbstractTableImpl):
validate_table_args(tbl)
return tbl.collect_scalar()


@builtin_verb()
def build_query(tbl: AbstractTableImpl):
return tbl.build_query()
Expand Down
12 changes: 10 additions & 2 deletions src/pydiverse/transform/eager/pandas_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ class PandasTableImpl(EagerTableImpl):
computed at some point. This allows for a more lazy style API.
"""

def __init__(self, name: str, df: pd.DataFrame):
self.df = fast_pd_convert_dtypes(df)
def __init__(self, name: str, df: pd.DataFrame, convert_dtypes_to_ensure_semantics=True):
if convert_dtypes_to_ensure_semantics:
self.df = fast_pd_convert_dtypes(df)
else:
self.df = df
self.join_translator = self.JoinTranslator()

columns = {
Expand Down Expand Up @@ -133,6 +136,11 @@ def collect(self) -> pd.DataFrame:
result.attrs["name"] = self.name
return result

def collect_scalar(self) -> int | float | str | bool: # TODO-in-this-pr: maybe-more?
collect = self.collect()
assert collect.shape == (1, 1) # TODO in this PR: assert with if
return self.collect().iloc[0, 0]

def mutate(self, **kwargs):
uuid_kwargs = {self.named_cols.fwd[k]: (k, v) for k, v in kwargs.items()}
self.df_name_mapping.update(
Expand Down

0 comments on commit 090d32b

Please sign in to comment.