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

Reimplement Kolmogorov Smirnov query logic with sqlalchemy's Language Expression API #44

Merged
merged 20 commits into from
Aug 1, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/datajudge/db_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ def get_column(self, engine):
f"Trying to access column of DataReference "
f"{self.get_string()} yet none is given."
)
return self.get_columns(engine)[0]
columns = self.get_columns(engine)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this one

(col,) = self.get_columns(engine)
return col

if len(columns) > 1:
raise ValueError(
"DataReference was expected to only have a single column but had multiple: "
f"{columns}"
)
return columns[0]

def get_columns(self, engine):
"""Fetch all relevant columns of a DataReference."""
Expand Down Expand Up @@ -905,6 +911,12 @@ def get_column_array_agg(


def _cdf_selection(engine, ref: DataReference, cdf_label: str, value_label: str):
"""Create an empirical cumulative distribution function values.

Concretely, create a selection with values from ``value_label`` as well as
the empirical cumulative didistribution function values, labeled as
``cdf_label``.
"""
col = ref.get_column(engine)
selection = ref.get_selection(engine).subquery()

Expand All @@ -927,7 +939,6 @@ def _cdf_selection(engine, ref: DataReference, cdf_label: str, value_label: str)
.group_by(cdf_selection.c[value_label])
.subquery()
)

return grouped_cdf_selection


Expand Down Expand Up @@ -1026,7 +1037,10 @@ def get_ks_2sample(
ref2: DataReference,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you not annotate return types?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Am I missing a comment somewhere? What's the idea? Shouldn't we annotate as much as possible?
Even using Any makes sense because you are proactively declaring that you don't care while not annotating leaves the user to guess where it's (1) unknown (2) not important (3) missing

Copy link
Collaborator Author

@kklein kklein Aug 1, 2022

Choose a reason for hiding this comment

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

Am I missing a comment somewhere?

Have you read this [0]?

because you are proactively declaring that you don't care

It's not clear to me why we don't care.

[0] #44 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll take the liberty to merge for now. Yet, if you consider this an open topic still, happy to further discuss this and address it as a follow-up @YYYasin19 .

"""
Runs the query for the two-sample Kolmogorov-Smirnov test and returns the test statistic d.
Run the query for the two-sample Kolmogorov-Smirnov test and return the test statistic d.

For a raw-sql version of this query, please see this PR:
https://github.com/Quantco/datajudge/pull/28/
"""
cdf_label = "cdf"
value_label = "val"
Expand Down