Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a "Discover" object for finding candidate tables that may be joined on the main table #1153

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var/
.installed.cfg
*.egg
*.pkl
data/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to ignore the files I am using locally to test the object.


data/

.pytest_cache/

Expand Down
24 changes: 24 additions & 0 deletions 10_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# %%
import polars as pl

from skrub._discover import Discover, find_unique_values

# %%
# working with binary to debug
data_lake_path = "data/binary_update/*.parquet"
base_table_path = "data/source_tables/company_employees-yadl-depleted.parquet"
query_column = "col_to_embed"


base_table = pl.read_parquet(base_table_path)
# %%
find_unique_values(base_table, ["col_to_embed"])
# %%
discover = Discover(data_lake_path, [query_column])
print("fitting")
discover.fit(base_table)
print("transforming")
ranking = discover.transform(base_table)
print(ranking)

# %%
18 changes: 18 additions & 0 deletions main_discover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import polars as pl

from skrub._discover import Discover

if __name__ == "__main__":
# working with binary to debug
data_lake_path = "data/binary_update/*.parquet"
base_table_path = "data/source_tables/yadl/movies_large-yadl-depleted.parquet"
query_column = "col_to_embed"

base_table = pl.read_parquet(base_table_path)

discover = Discover(data_lake_path, [query_column])
print("fitting")
discover.fit(base_table)
print("transforming")
joined_table = discover.transform(base_table)
print(joined_table)
42 changes: 42 additions & 0 deletions skrub/_dataframe/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
"col_by_idx",
"collect",
#
# Loading data
#
"read_parquet",
"read_csv",
#
# Querying and modifying metadata
#
"shape",
Expand Down Expand Up @@ -397,6 +402,43 @@ def _collect_polars_lazyframe(df):
return df.collect()


#
# Loading data
# ============
#


# TODO: Adding X here as a placeholder to get around the type check,
@dispatch
def read_parquet(X, input_path):
raise NotImplementedError()


@read_parquet.specialize("pandas", argument_type=["DataFrame"])
def _read_parquet_pandas(X, input_path):
return pd.read_parquet(input_path)


@read_parquet.specialize("polars", argument_type=["DataFrame"])
def _read_parquet_polars(X, input_path):
return pl.read_parquet(input_path)


@dispatch
def read_csv(X, input_path):
raise NotImplementedError()


@read_csv.specialize("pandas", argument_type=["DataFrame"])
def _read_csv_pandas(X, input_path):
return pd.read_csv(input_path)


@read_csv.specialize("polars", argument_type=["DataFrame"])
def _read_csv_polars(X, input_path):
return pl.read_csv(input_path)


#
# Querying and modifying metadata
# ===============================
Expand Down
Loading
Loading