Skip to content

Commit a38d4c4

Browse files
arwas11tswast
andauthored
docs: update DataFrame docstrings to include the errors section (#1127)
* docs: update DataFrame docstrings to include the errors section. * Fix markup * Update third_party/bigframes_vendored/pandas/core/frame.py --------- Co-authored-by: Tim Sweña (Swast) <[email protected]>
1 parent 65e2e70 commit a38d4c4

File tree

2 files changed

+201
-26
lines changed

2 files changed

+201
-26
lines changed

third_party/bigframes_vendored/pandas/core/frame.py

+186-24
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,19 @@ def to_gbq(
487487
str:
488488
The fully-qualified ID for the written table, in the form
489489
``project.dataset.tablename``.
490+
491+
Raises:
492+
ValueError:
493+
If an invalid value is provided for ``if_exists`` when ``destination_table``
494+
is ``None``. ``None`` or ``replace`` are the only valid values for ``if_exists``.
495+
ValueError:
496+
If an invalid value is provided for ``destination_table`` that is
497+
not one of ``datasetID.tableId`` or ``projectId.datasetId.tableId``.
498+
ValueError:
499+
If an invalid value is provided for ``if_exists`` that is not one of
500+
``fail``, ``replace``, or ``append``.
501+
502+
490503
"""
491504
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
492505

@@ -531,7 +544,13 @@ def to_parquet(
531544
If ``False``, they will not be written to the file.
532545
533546
Returns:
534-
None or bytes: bytes if no path argument is provided else None
547+
None or bytes:
548+
bytes if no path argument is provided else None
549+
550+
Raises:
551+
ValueError:
552+
If an invalid value provided for `compression` that is not one of
553+
``None``, ``snappy``, or ``gzip``.
535554
"""
536555
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
537556

@@ -1140,9 +1159,11 @@ def insert(self, loc, column, value, allow_duplicates=False):
11401159
Allow duplicate column labels to be created.
11411160
11421161
Raises:
1162+
IndexError:
1163+
If ``column`` index is out of bounds with the total count of columns.
11431164
ValueError:
1144-
If `column` is already contained in the DataFrame,
1145-
unless `allow_duplicates` is set to True.
1165+
If ``column`` is already contained in the DataFrame,
1166+
unless ``allow_duplicates`` is set to True.
11461167
"""
11471168
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
11481169

@@ -1259,10 +1280,14 @@ def drop(
12591280
level:
12601281
For MultiIndex, level from which the labels will be removed.
12611282
Returns:
1262-
bigframes.pandas.DataFrame: DataFrame without the removed column labels.
1283+
bigframes.pandas.DataFrame:
1284+
DataFrame without the removed column labels.
12631285
12641286
Raises:
12651287
KeyError: If any of the labels is not found in the selected axis.
1288+
ValueError: If values for both ``labels`` and ``index``/``columns`` are provided.
1289+
ValueError: If a multi-index tuple is provided as ``level``.
1290+
ValueError: If either ``labels`` or ``index``/``columns`` is not provided.
12661291
"""
12671292
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
12681293

@@ -1419,7 +1444,12 @@ def set_index(
14191444
Delete columns to be used as the new index.
14201445
14211446
Returns:
1422-
bigframes.pandas.DataFrame: Changed row labels.
1447+
bigframes.pandas.DataFrame:
1448+
Changed row labels.
1449+
1450+
Raises:
1451+
KeyError:
1452+
If key(s) are not in the columns.
14231453
"""
14241454
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
14251455

@@ -1437,7 +1467,12 @@ def reorder_levels(
14371467
Where to reorder levels.
14381468
14391469
Returns:
1440-
bigframes.pandas.DataFrame: DataFrame of rearranged index.
1470+
bigframes.pandas.DataFrame:
1471+
DataFrame of rearranged index.
1472+
1473+
Raises:
1474+
ValueError:
1475+
If columns are not multi-index.
14411476
"""
14421477
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
14431478

@@ -1455,7 +1490,12 @@ def swaplevel(self, i, j, axis: str | int = 0) -> DataFrame:
14551490
'columns' for column-wise.
14561491
14571492
Returns:
1458-
bigframes.pandas.DataFrame: DataFrame with levels swapped in MultiIndex.
1493+
bigframes.pandas.DataFrame:
1494+
DataFrame with levels swapped in MultiIndex.
1495+
1496+
Raises:
1497+
ValueError:
1498+
If columns are not multi-index.
14591499
"""
14601500
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
14611501

@@ -1474,7 +1514,12 @@ def droplevel(self, level, axis: str | int = 0):
14741514
* 0 or 'index': remove level(s) in column.
14751515
* 1 or 'columns': remove level(s) in row.
14761516
Returns:
1477-
bigframes.pandas.DataFrame: DataFrame with requested index / column level(s) removed.
1517+
bigframes.pandas.DataFrame:
1518+
DataFrame with requested index / column level(s) removed.
1519+
1520+
Raises:
1521+
ValueError:
1522+
If columns are not multi-index
14781523
"""
14791524
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
14801525

@@ -1724,7 +1769,12 @@ def dropna(
17241769
17251770
17261771
Returns:
1727-
bigframes.pandas.DataFrame: DataFrame with NA entries dropped from it.
1772+
bigframes.pandas.DataFrame:
1773+
DataFrame with NA entries dropped from it.
1774+
1775+
Raises:
1776+
ValueError:
1777+
If ``how`` is not one of ``any`` or ``all``.
17281778
"""
17291779
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
17301780

@@ -1772,8 +1822,13 @@ def isin(self, values):
17721822
the column names, which must match.
17731823
17741824
Returns:
1775-
bigframes.pandas.DataFrame: DataFrame of booleans showing whether each element
1776-
in the DataFrame is contained in values.
1825+
bigframes.pandas.DataFrame:
1826+
DataFrame of booleans showing whether each element
1827+
in the DataFrame is contained in values.
1828+
1829+
Raises:
1830+
TypeError:
1831+
If values provided are not list-like objects.
17771832
"""
17781833
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
17791834

@@ -2004,7 +2059,12 @@ def sort_values(
20042059
if `first`; `last` puts NaNs at the end.
20052060
20062061
Returns:
2007-
bigframes.pandas.DataFrame: DataFrame with sorted values.
2062+
bigframes.pandas.DataFrame:
2063+
DataFrame with sorted values.
2064+
2065+
Raises:
2066+
ValueError:
2067+
If value of ``na_position`` is not one of ``first`` or ``last``.
20082068
"""
20092069
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
20102070

@@ -2014,7 +2074,14 @@ def sort_index(
20142074
"""Sort object by labels (along an axis).
20152075
20162076
Returns:
2017-
bigframes.pandas.DataFrame: The original DataFrame sorted by the labels.
2077+
bigframes.pandas.DataFrame:
2078+
The original DataFrame sorted by the labels.
2079+
2080+
Raises:
2081+
ValueError:
2082+
If value of ``na_position`` is not one of ``first`` or ``last``.
2083+
ValueError:
2084+
If length of ``ascending`` dose not equal length of ``by``.
20182085
"""
20192086
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
20202087

@@ -3727,7 +3794,12 @@ def combine(
37273794
overwritten with NaNs.
37283795
37293796
Returns:
3730-
bigframes.pandas.DataFrame: Combination of the provided DataFrames.
3797+
bigframes.pandas.DataFrame:
3798+
Combination of the provided DataFrames.
3799+
3800+
Raises:
3801+
ValueError:
3802+
If ``func`` return value is not Series.
37313803
"""
37323804
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
37333805

@@ -3813,8 +3885,17 @@ def explode(
38133885
If True, the resulting index will be labeled 0, 1, …, n - 1.
38143886
38153887
Returns:
3816-
bigframes.pandas.DataFrame: Exploded lists to rows of the subset columns;
3888+
bigframes.pandas.DataFrame:
3889+
Exploded lists to rows of the subset columns;
38173890
index will be duplicated for these rows.
3891+
3892+
Raises:
3893+
ValueError:
3894+
* If columns of the frame are not unique.
3895+
* If specified columns to explode is empty list.
3896+
* If specified columns to explode have not matching count of elements rowwise in the frame.
3897+
KeyError:
3898+
If incorrect column names are provided
38183899
"""
38193900
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
38203901

@@ -3929,6 +4010,10 @@ def update(
39294010
39304011
Returns:
39314012
None: This method directly changes calling object.
4013+
4014+
Raises:
4015+
ValueError:
4016+
If a type of join other than ``left`` is provided as an argument.
39324017
"""
39334018
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
39344019

@@ -4023,7 +4108,14 @@ def groupby(
40234108
values will also be treated as the key in groups.
40244109
40254110
Returns:
4026-
bigframes.core.groupby.SeriesGroupBy: A groupby object that contains information about the groups.
4111+
bigframes.core.groupby.SeriesGroupBy:
4112+
A groupby object that contains information about the groups.
4113+
4114+
Raises:
4115+
ValueError:
4116+
If both ``by`` and ``level`` are specified.
4117+
TypeError:
4118+
If one of ``by`` or `level`` is not specified.
40274119
"""
40284120
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
40294121

@@ -4109,7 +4201,14 @@ def map(self, func, na_action: Optional[str] = None) -> DataFrame:
41094201
values, without passing them to func.
41104202
41114203
Returns:
4112-
bigframes.pandas.DataFrame: Transformed DataFrame.
4204+
bigframes.pandas.DataFrame:
4205+
Transformed DataFrame.
4206+
4207+
Raises:
4208+
TypeError:
4209+
If value provided for ``func`` is not callable.
4210+
ValueError:
4211+
If value provided for ``na_action`` is not ``None`` or ``ignore``.
41134212
"""
41144213
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
41154214

@@ -4209,7 +4308,18 @@ def join(self, other, *, on: Optional[str] = None, how: str) -> DataFrame:
42094308
the order of the left keys.
42104309
42114310
Returns:
4212-
bigframes.pandas.DataFrame: A dataframe containing columns from both the caller and `other`.
4311+
bigframes.pandas.DataFrame:
4312+
A dataframe containing columns from both the caller and `other`.
4313+
4314+
Raises:
4315+
ValueError:
4316+
If value for ``on`` is specified for cross join.
4317+
ValueError:
4318+
If join on columns does not match the index level of the other
4319+
DataFrame. Join on columns with multi-index is not supported.
4320+
ValueError:
4321+
If left index to join on does not have the same number of levels
4322+
as the right index.
42134323
"""
42144324
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
42154325

@@ -4354,7 +4464,20 @@ def merge(
43544464
no suffix. At least one of the values must not be None.
43554465
43564466
Returns:
4357-
bigframes.pandas.DataFrame: A DataFrame of the two merged objects.
4467+
bigframes.pandas.DataFrame:
4468+
A DataFrame of the two merged objects.
4469+
4470+
Raises:
4471+
ValueError:
4472+
If value for ``on`` is specified for cross join.
4473+
ValueError:
4474+
If ``on`` or ``left_on`` + ``right_on`` are not specified when ``on`` is ``None``.
4475+
ValueError:
4476+
If ``on`` and ``left_on`` + ``right_on`` are specified when ``on`` is not ``None``.
4477+
ValueError:
4478+
If no column with the provided label is found in ``self`` for left join.
4479+
ValueError:
4480+
If no column with the provided label is found in ``self`` for right join.
43584481
"""
43594482
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
43604483

@@ -4469,6 +4592,16 @@ def apply(self, func, *, axis=0, args=(), **kwargs):
44694592
Returns:
44704593
bigframes.pandas.DataFrame or bigframes.pandas.Series:
44714594
Result of applying ``func`` along the given axis of the DataFrame.
4595+
4596+
Raises:
4597+
ValueError:
4598+
If a remote function is not provided when ``axis=1`` is specified.
4599+
ValueError:
4600+
If number or input params in the remote function are not the same as
4601+
the number of columns in the dataframe.
4602+
ValueError:
4603+
If the dtypes of the columns in the dataframe are not compatible with
4604+
the data types of the remote function input params.
44724605
"""
44734606
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
44744607

@@ -5156,7 +5289,12 @@ def nlargest(self, n: int, columns, keep: str = "first"):
51565289
selecting more than `n` items.
51575290
51585291
Returns:
5159-
bigframes.pandas.DataFrame: The first `n` rows ordered by the given columns in descending order.
5292+
bigframes.pandas.DataFrame:
5293+
The first `n` rows ordered by the given columns in descending order.
5294+
5295+
Raises:
5296+
ValueError:
5297+
If value of ``keep`` is not ``first``, ``last``, or ``all``.
51605298
"""
51615299
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
51625300

@@ -5244,7 +5382,12 @@ def nsmallest(self, n: int, columns, keep: str = "first"):
52445382
selecting more than `n` items.
52455383
52465384
Returns:
5247-
bigframes.pandas.DataFrame: The first `n` rows ordered by the given columns in ascending order.
5385+
bigframes.pandas.DataFrame:
5386+
The first `n` rows ordered by the given columns in ascending order.
5387+
5388+
Raises:
5389+
ValueError:
5390+
If value of ``keep`` is not ``first``, ``last``, or ``all``.
52485391
"""
52495392
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
52505393

@@ -5513,7 +5656,12 @@ def cumsum(self) -> DataFrame:
55135656
[3 rows x 2 columns]
55145657
55155658
Returns:
5516-
bigframes.pandas.DataFrame: Return cumulative sum of DataFrame.
5659+
bigframes.pandas.DataFrame:
5660+
Return cumulative sum of DataFrame.
5661+
5662+
Raises:
5663+
ValueError:
5664+
If values are not of numeric type.
55175665
"""
55185666
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
55195667

@@ -5545,7 +5693,12 @@ def cumprod(self) -> DataFrame:
55455693
[3 rows x 2 columns]
55465694
55475695
Returns:
5548-
bigframes.pandas.DataFrame: Return cumulative product of DataFrame.
5696+
bigframes.pandas.DataFrame:
5697+
Return cumulative product of DataFrame.
5698+
5699+
Raises:
5700+
ValueError:
5701+
If values are not of numeric type.
55495702
"""
55505703
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
55515704

@@ -5695,7 +5848,12 @@ def describe(self):
56955848
[8 rows x 2 columns]
56965849
56975850
Returns:
5698-
bigframes.pandas.DataFrame: Summary statistics of the Series or Dataframe provided.
5851+
bigframes.pandas.DataFrame:
5852+
Summary statistics of the Series or Dataframe provided.
5853+
5854+
Raises:
5855+
ValueError:
5856+
If unsupported ``include`` type is provided.
56995857
"""
57005858
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
57015859

@@ -6679,6 +6837,10 @@ def dot(self, other):
66796837
If `other` is a Series, return the matrix product between self and
66806838
other as a Series. If other is a DataFrame, return
66816839
the matrix product of self and other in a DataFrame.
6840+
6841+
Raises:
6842+
RuntimeError:
6843+
If unable to construct all columns.
66826844
"""
66836845
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
66846846

0 commit comments

Comments
 (0)