Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions bigframes/_tools/docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def inherit_docs(source_class):
"""
A class decorator that copies docstrings from source_class to the
decorated class for any methods or attributes that match names.
"""

def decorator(target_class):
if not target_class.__doc__ and source_class.__doc__:
target_class.__doc__ = source_class.__doc__

for name, source_item in vars(source_class).items():
if name in vars(target_class):
target_item = getattr(target_class, name)

if hasattr(target_item, "__doc__") and not target_item.__doc__:
if hasattr(source_item, "__doc__") and source_item.__doc__:
try:
target_item.__doc__ = source_item.__doc__
except AttributeError:
pass
Comment on lines +23 to +35
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to raise an error if both the target and the source have docs, assuming that all the docs should be placed in that vendored directory?


return target_class

return decorator
6 changes: 3 additions & 3 deletions bigframes/core/groupby/dataframe_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pandas as pd

from bigframes import session
from bigframes._tools import docs
from bigframes.core import agg_expressions
from bigframes.core import expression as ex
import bigframes.core.block_transforms as block_ops
Expand All @@ -44,9 +45,8 @@


@log_adapter.class_logger
class DataFrameGroupBy(vendored_pandas_groupby.DataFrameGroupBy):
__doc__ = vendored_pandas_groupby.GroupBy.__doc__

@docs.inherit_docs(vendored_pandas_groupby.DataFrameGroupBy)
class DataFrameGroupBy:
def __init__(
self,
block: blocks.Block,
Expand Down
4 changes: 2 additions & 2 deletions bigframes/core/groupby/series_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pandas

from bigframes import session
from bigframes._tools import docs
from bigframes.core import expression as ex
import bigframes.core.block_transforms as block_ops
import bigframes.core.blocks as blocks
Expand All @@ -43,9 +44,8 @@


@log_adapter.class_logger
@docs.inherit_docs(vendored_pandas_groupby.SeriesGroupBy)
class SeriesGroupBy(vendored_pandas_groupby.SeriesGroupBy):
__doc__ = vendored_pandas_groupby.GroupBy.__doc__

def __init__(
self,
block: blocks.Block,
Expand Down
10 changes: 8 additions & 2 deletions bigframes/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pandas

from bigframes import dtypes
from bigframes._tools import docs
import bigframes.core.agg_expressions as ex_types
import bigframes.core.block_transforms as block_ops
import bigframes.core.blocks as blocks
Expand All @@ -47,8 +48,8 @@
import bigframes.series


class Index(vendored_pandas_index.Index):
__doc__ = vendored_pandas_index.Index.__doc__
@docs.inherit_docs(vendored_pandas_index.Index)
class Index:
_query_job = None
_block: blocks.Block
_linked_frame: Union[
Expand Down Expand Up @@ -777,6 +778,11 @@ def to_list(self, *, allow_large_results: Optional[bool] = None) -> list:
def __len__(self):
return self.shape[0]

def __bool__(self):
raise ValueError(
"Cannot convert Index into bool. Consider using .empty(), .item(), .any(), or .all() methods."
)

def item(self):
# Docstring is in third_party/bigframes_vendored/pandas/core/indexes/base.py
return self.to_series().peek(2).item()
Expand Down
5 changes: 3 additions & 2 deletions bigframes/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
datetimes as vendored_pandas_datetime_index,
)

from bigframes._tools import docs
from bigframes.core import expression as ex
from bigframes.core.indexes.base import Index
from bigframes.operations import date_ops


class DatetimeIndex(Index, vendored_pandas_datetime_index.DatetimeIndex):
__doc__ = vendored_pandas_datetime_index.DatetimeIndex.__doc__
@docs.inherit_docs(vendored_pandas_datetime_index.DatetimeIndex)
class DatetimeIndex(Index):

# Must be above 5000 for pandas to delegate to bigframes for binops
__pandas_priority__ = 12000
Expand Down
6 changes: 3 additions & 3 deletions bigframes/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import bigframes_vendored.pandas.core.indexes.multi as vendored_pandas_multindex
import pandas

from bigframes._tools import docs
from bigframes.core import blocks
from bigframes.core import expression as ex
from bigframes.core.indexes.base import Index
Expand All @@ -27,9 +28,8 @@
import bigframes.session


class MultiIndex(Index, vendored_pandas_multindex.MultiIndex):
__doc__ = vendored_pandas_multindex.MultiIndex.__doc__

@docs.inherit_docs(vendored_pandas_multindex.MultiIndex)
class MultiIndex(Index):
@classmethod
def from_tuples(
cls,
Expand Down
6 changes: 3 additions & 3 deletions bigframes/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pandas

from bigframes import dtypes
from bigframes._tools import docs
from bigframes.core import agg_expressions
from bigframes.core import expression as ex
from bigframes.core import ordering, utils, window_spec
Expand All @@ -36,9 +37,8 @@


@log_adapter.class_logger
class Window(vendored_pandas_rolling.Window):
__doc__ = vendored_pandas_rolling.Window.__doc__

@docs.inherit_docs(vendored_pandas_rolling.Window)
class Window:
def __init__(
self,
block: blocks.Block,
Expand Down
Loading
Loading