Skip to content

Commit 81f49a6

Browse files
committed
avoid setting column labels in special case of Series(block)
1 parent 841bc64 commit 81f49a6

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

bigframes/operations/base.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,6 @@ def __init__(
8484
f"Series constructor only supports copy=True. {constants.FEEDBACK_LINK}"
8585
)
8686

87-
if name is DEFAULT:
88-
if isinstance(data, blocks.Block):
89-
name = data.column_labels[0]
90-
elif hasattr(data, "name"):
91-
name = getattr(data, "name")
92-
elif hasattr(data, "_name"):
93-
name = getattr(data, "_name")
94-
else:
95-
name = None
96-
9787
if isinstance(data, blocks.Block):
9888
block = data
9989
elif isinstance(data, SeriesMethods):
@@ -139,6 +129,8 @@ def __init__(
139129
idx_cols = idx_block.index_columns
140130
block, _ = idx_block.join(block, how="left")
141131
block = block.with_index_labels(bf_index.names)
132+
if name is not DEFAULT:
133+
block = block.with_column_labels([name])
142134
if dtype:
143135
bf_dtype = bigframes.dtypes.bigframes_type(dtype)
144136
block = block.multi_apply_unary_op(ops.AsTypeOp(to_type=bf_dtype))
@@ -150,14 +142,14 @@ def __init__(
150142
data=data,
151143
index=index, # type:ignore
152144
dtype=dtype, # type:ignore
153-
name=name,
145+
name=name if name is not DEFAULT else None,
154146
)
155147
name = pd_series.name # type: ignore
156148
block = read_pandas_func(pd_series)._get_block() # type:ignore
149+
block = block.with_column_labels([name])
157150

158151
assert block is not None
159152

160-
block = block.with_column_labels([name])
161153
self._block: blocks.Block = block
162154

163155
@property

bigframes/session/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ def udf(
18291829
Turning an arbitrary python function into a BigQuery managed python udf:
18301830
18311831
>>> bq_name = datetime.datetime.now().strftime("bigframes_%Y%m%d%H%M%S%f")
1832-
>>> @bpd.udf(dataset="bigfranes_testing", name=bq_name)
1832+
>>> @bpd.udf(dataset="bigfranes_testing", name=bq_name) # doctest: +SKIP
18331833
... def minutes_to_hours(x: int) -> float:
18341834
... return x/60
18351835
@@ -1842,8 +1842,8 @@ def udf(
18421842
4 120
18431843
dtype: Int64
18441844
1845-
>>> hours = minutes.apply(minutes_to_hours)
1846-
>>> hours
1845+
>>> hours = minutes.apply(minutes_to_hours) # doctest: +SKIP
1846+
>>> hours # doctest: +SKIP
18471847
0 0.0
18481848
1 0.5
18491849
2 1.0
@@ -1856,7 +1856,7 @@ def udf(
18561856
packages (optionally with the package version) via `packages` param.
18571857
18581858
>>> bq_name = datetime.datetime.now().strftime("bigframes_%Y%m%d%H%M%S%f")
1859-
>>> @bpd.udf(
1859+
>>> @bpd.udf( # doctest: +SKIP
18601860
... dataset="bigfranes_testing",
18611861
... name=bq_name,
18621862
... packages=["cryptography"]
@@ -1873,14 +1873,14 @@ def udf(
18731873
... return f.encrypt(input.encode()).decode()
18741874
18751875
>>> names = bpd.Series(["Alice", "Bob"])
1876-
>>> hashes = names.apply(get_hash)
1876+
>>> hashes = names.apply(get_hash) # doctest: +SKIP
18771877
18781878
You can clean-up the BigQuery functions created above using the BigQuery
18791879
client from the BigQuery DataFrames session:
18801880
18811881
>>> session = bpd.get_global_session()
1882-
>>> session.bqclient.delete_routine(minutes_to_hours.bigframes_bigquery_function)
1883-
>>> session.bqclient.delete_routine(get_hash.bigframes_bigquery_function)
1882+
>>> session.bqclient.delete_routine(minutes_to_hours.bigframes_bigquery_function) # doctest: +SKIP
1883+
>>> session.bqclient.delete_routine(get_hash.bigframes_bigquery_function) # doctest: +SKIP
18841884
18851885
Args:
18861886
input_types (type or sequence(type), Optional):

0 commit comments

Comments
 (0)