Skip to content

Commit 8588e72

Browse files
committed
undo changes in tile.py
1 parent 920f673 commit 8588e72

File tree

2 files changed

+27
-11
lines changed
  • bigframes/core/reshape
  • tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_qcut

2 files changed

+27
-11
lines changed

bigframes/core/reshape/tile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import pandas as pd
2323

2424
import bigframes
25+
import bigframes.constants
26+
import bigframes.core.expression as ex
2527
import bigframes.core.ordering as order
2628
import bigframes.core.utils as utils
2729
import bigframes.core.window_spec as window_specs
@@ -163,6 +165,7 @@ def qcut(
163165
f"Only duplicates='drop' is supported in BigQuery DataFrames so far. {constants.FEEDBACK_LINK}"
164166
)
165167
block = x._block
168+
label = block.col_id_to_label[x._value_column]
166169
block, nullity_id = block.apply_unary_op(x._value_column, ops.notnull_op)
167170
block, result = block.apply_window_op(
168171
x._value_column,
@@ -172,6 +175,9 @@ def qcut(
172175
ordering=(order.ascending_over(x._value_column),),
173176
),
174177
)
178+
block, result = block.project_expr(
179+
ops.where_op.as_expr(result, nullity_id, ex.const(None)), label=label
180+
)
175181
return bigframes.series.Series(block.select_column(result))
176182

177183

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_qcut/out.sql

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,39 @@ WITH `bfcte_0` AS (
2323
), `bfcte_3` AS (
2424
SELECT
2525
*,
26-
NOT `int64_col` IS NULL AS `bfcol_9`
26+
IF(`bfcol_4`, `bfcol_5`, NULL) AS `bfcol_6`
2727
FROM `bfcte_2`
2828
), `bfcte_4` AS (
29+
SELECT
30+
*,
31+
NOT `int64_col` IS NULL AS `bfcol_10`
32+
FROM `bfcte_3`
33+
), `bfcte_5` AS (
2934
SELECT
3035
*,
3136
CASE
32-
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_9` ORDER BY `int64_col` ASC) < 0
37+
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_10` ORDER BY `int64_col` ASC) < 0
3338
THEN NULL
34-
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_9` ORDER BY `int64_col` ASC) <= 0.25
39+
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_10` ORDER BY `int64_col` ASC) <= 0.25
3540
THEN 0
36-
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_9` ORDER BY `int64_col` ASC) <= 0.5
41+
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_10` ORDER BY `int64_col` ASC) <= 0.5
3742
THEN 1
38-
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_9` ORDER BY `int64_col` ASC) <= 0.75
43+
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_10` ORDER BY `int64_col` ASC) <= 0.75
3944
THEN 2
40-
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_9` ORDER BY `int64_col` ASC) <= 1
45+
WHEN PERCENT_RANK() OVER (PARTITION BY `bfcol_10` ORDER BY `int64_col` ASC) <= 1
4146
THEN 3
4247
ELSE NULL
43-
END AS `bfcol_10`
44-
FROM `bfcte_3`
48+
END AS `bfcol_11`
49+
FROM `bfcte_4`
50+
), `bfcte_6` AS (
51+
SELECT
52+
*,
53+
IF(`bfcol_10`, `bfcol_11`, NULL) AS `bfcol_12`
54+
FROM `bfcte_5`
4555
)
4656
SELECT
4757
`rowindex`,
4858
`int64_col`,
49-
`bfcol_5` AS `qcut_w_int`,
50-
`bfcol_10` AS `qcut_w_list`
51-
FROM `bfcte_4`
59+
`bfcol_6` AS `qcut_w_int`,
60+
`bfcol_12` AS `qcut_w_list`
61+
FROM `bfcte_6`

0 commit comments

Comments
 (0)