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

refactor: complete dtype rules for expression tree transformations #376

Merged
merged 36 commits into from
Mar 20, 2024

Conversation

TrevorBergeron
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Feb 8, 2024
@TrevorBergeron TrevorBergeron force-pushed the typestypes branch 3 times, most recently from 2d26785 to 1b79355 Compare February 8, 2024 21:15
@TrevorBergeron TrevorBergeron changed the title perf: derive expression schema without ibis compilation refactor: complete dtype rules for expression tree transformations Mar 6, 2024
@TrevorBergeron TrevorBergeron marked this pull request as ready for review March 6, 2024 22:16
@TrevorBergeron TrevorBergeron requested review from a team as code owners March 6, 2024 22:16
@TrevorBergeron TrevorBergeron requested review from chelsea-lin and removed request for ashleyxuu March 14, 2024 17:44
Copy link
Contributor

@chelsea-lin chelsea-lin left a comment

Choose a reason for hiding this comment

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

After learning more details offline, overall LGTM!

Copy link
Contributor

@chelsea-lin chelsea-lin left a comment

Choose a reason for hiding this comment

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

Left few questions. LGTM overall.

3 <NA>
4 <NA>
dtype: Float64
dtype: Int64
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to see that this change fix this issue!

inline_df = dataframe.DataFrame(
blocks.Block.from_local(pandas_dataframe, self)
)
except ValueError: # Thrown by ibis for some unhandled tyeps
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -146,6 +205,24 @@ def skips_nulls(self):
def handles_ties(self):
return True

def output_type(self, *input_types: dtypes.ExpressionType):
if isinstance(self.bins, int) and (self.labels is False):
return dtypes.INT_DTYPE
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 have a chance to test it? Is it FLOAT_DTYPE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the test suite automatically validates all these derivations now


@dataclasses.dataclass(frozen=True)
class MeanOp(UnaryAggregateOp):
name: ClassVar[str] = "mean"

def output_type(self, *input_types: dtypes.ExpressionType):
if pd.api.types.is_bool_dtype(input_types[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

if pd.api.types.is_bool_dtype(input_types[0]) or pd.api.types.is_integer_dtype(input_types[0]):
   return dtypes.FLOAT_DTYPE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -87,16 +112,38 @@ class ApproxQuartilesOp(UnaryAggregateOp):
def name(self):
return f"{self.quartile*25}%"

def output_type(self, *input_types: dtypes.ExpressionType):
if pd.api.types.is_bool_dtype(input_types[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

same as below

if not isinstance(x, ibis_types.DecimalValue):
return False
# Should be exactly 76 for bignumeric
return x.precision > 70
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update it into == 76 as you handle the numeric casting at line 1102 in this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I care about the pre-cast type information, and I don't trust ibis to have the precision/scale numbers right.

@TrevorBergeron TrevorBergeron merged commit 43d0864 into main Mar 20, 2024
14 of 15 checks passed
@TrevorBergeron TrevorBergeron deleted the typestypes branch March 20, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants