From ae76a5f12bdce256b2dd7abccfcf5ce97784805e Mon Sep 17 00:00:00 2001 From: Arwa Date: Thu, 21 Nov 2024 14:01:59 -0600 Subject: [PATCH 1/7] docs: add third party pandas.Index methods and docstrings --- .../pandas/core/indexes/base.py | 170 +++++++++++++++++- 1 file changed, 168 insertions(+), 2 deletions(-) diff --git a/third_party/bigframes_vendored/pandas/core/indexes/base.py b/third_party/bigframes_vendored/pandas/core/indexes/base.py index b0e1a09392..5a267d3cd7 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/base.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/base.py @@ -25,8 +25,13 @@ class Index: """ @property - def name(self): - """Returns Index name.""" + def names(self): + """Returns the names of the Index. + + Returns: + Sequence[blocks.Label]: + A Sequence of Index or MultiIndex name + """ raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) @property @@ -34,6 +39,167 @@ def values(self): """Return an array representing the data in the Index.""" raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + @property + def ndim(self): + """ + Number of dimensions of the underlying data, by definition 1. + + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> s = bpd.Series(['Ant', 'Bear', 'Cow']) + >>> s + 0 Ant + 1 Bear + 2 Cow + dtype: string + + >>> s.ndim + 1 + + For Index: + + >>> idx = bpd.Index([1, 2, 3]) + >>> idx + Index([1, 2, 3], dtype='Int64') + + >>> idx.ndim + 1 + + Returns: + int: + Number or dimensions. + """ + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + + @property + def size(self) -> int: + """Return the number of elements in the underlying data. + + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + For Series: + + >>> s = bpd.Series(['Ant', 'Bear', 'Cow']) + >>> s + 0 Ant + 1 Bear + 2 Cow + dtype: string + + For Index: + + >>> idx = bpd.Index([1, 2, 3]) + >>> idx + 3 + + Returns: + int: + Number of elements + """ + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + + @property + def empty(self) -> bool: + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + + @property + def is_monotonic_increasing(self) -> bool: + """ + Return a boolean if the values are equal or increasing. + + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> bpd.Index([1, 2, 3]).is_monotonic_increasing + True + + >>> bpd.Index([1, 2, 2]).is_monotonic_increasing + True + + >>> bpd.Index([1, 3, 2]).is_monotonic_increasing + False + + Returns: + bool: + True, if the values monotonically increasing, otherwise False. + """ + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + + @property + def is_monotonic_decreasing(self) -> bool: + """ + Return a boolean if the values are equal or decreasing. + + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> bpd.Index([3, 2, 1]).is_monotonic_decreasing + True + + >>> bpd.Index([3, 2, 2]).is_monotonic_decreasing + True + + >>> bpd.Index([3, 1, 2]).is_monotonic_decreasing + False + + Returns: + bool: + True, if the values monotonically decreasing, otherwise False. + """ + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + + @classmethod + def from_frame(cls, frame) -> Index: + """ + Make a MultiIndex from a DataFrame. + + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> df = bpd.DataFrame([['HI', 'Temp'], ['HI', 'Precip'], + ... ['NJ', 'Temp'], ['NJ', 'Precip']], + ... columns=['a', 'b']) + >>> df + a b + 0 HI Temp + 1 HI Precip + 2 NJ Temp + 3 NJ Precip + 4 rows x 2 columns + + [4 rows x 2 columns in total] + + >>> bpd.MultiIndex.from_frame(df) + Index([0, 1, 2, 3], dtype='Int64') + + + Args: + frame (Union[bigframes.series.Series, bigframes.dataframe.DataFrame]): + bigframes.series.Series or bigframes.dataframe.DataFrame to convert + to bigframes.pandas.Index + + Returns: + bigframes.pandas.Index: + The Index representation of the given Series or DataFrame + + Raises: + bigframes.exceptions.NullIndexError: + If Index is Null + """ + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + @property def shape(self): """ From 5ab19ff27da24b2c489be9eb25d5c13fc548cbfa Mon Sep 17 00:00:00 2001 From: Arwa Date: Fri, 22 Nov 2024 16:21:51 -0600 Subject: [PATCH 2/7] fix indent error --- .../pandas/core/indexes/base.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/third_party/bigframes_vendored/pandas/core/indexes/base.py b/third_party/bigframes_vendored/pandas/core/indexes/base.py index 1f7cafccea..d2ac96ad59 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/base.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/base.py @@ -76,7 +76,8 @@ def ndim(self): @property def size(self) -> int: - """Return the number of elements in the underlying data. + """ + Return the number of elements in the underlying data. **Examples:** @@ -113,7 +114,7 @@ def is_monotonic_increasing(self) -> bool: """ Return a boolean if the values are equal or increasing. - **Examples:** + **Examples:** >>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None @@ -138,7 +139,7 @@ def is_monotonic_decreasing(self) -> bool: """ Return a boolean if the values are equal or decreasing. - **Examples:** + **Examples:** >>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None @@ -169,8 +170,8 @@ def from_frame(cls, frame) -> Index: >>> bpd.options.display.progress_bar = None >>> df = bpd.DataFrame([['HI', 'Temp'], ['HI', 'Precip'], - ... ['NJ', 'Temp'], ['NJ', 'Precip']], - ... columns=['a', 'b']) + ... ['NJ', 'Temp'], ['NJ', 'Precip']], + ... columns=['a', 'b']) >>> df a b 0 HI Temp @@ -184,19 +185,18 @@ def from_frame(cls, frame) -> Index: >>> bpd.MultiIndex.from_frame(df) Index([0, 1, 2, 3], dtype='Int64') - - Args: - frame (Union[bigframes.series.Series, bigframes.dataframe.DataFrame]): - bigframes.series.Series or bigframes.dataframe.DataFrame to convert - to bigframes.pandas.Index + Args: + frame (Union[bigframes.pandas.Series, bigframes.pandas.DataFrame]): + bigframes.pandas.Series or bigframes.pandas.DataFrame to convert + to bigframes.pandas.Index. Returns: bigframes.pandas.Index: - The Index representation of the given Series or DataFrame + The Index representation of the given Series or DataFrame. Raises: bigframes.exceptions.NullIndexError: - If Index is Null + If Index is Null. """ raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) From 4b35c05cb7284d1a1a051ac177d6ebd3958a8977 Mon Sep 17 00:00:00 2001 From: Arwa Date: Fri, 22 Nov 2024 16:54:25 -0600 Subject: [PATCH 3/7] updae bigframes.pandas.Index docstrings --- bigframes/core/indexes/base.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bigframes/core/indexes/base.py b/bigframes/core/indexes/base.py index a8445835dd..e88bf479a9 100644 --- a/bigframes/core/indexes/base.py +++ b/bigframes/core/indexes/base.py @@ -175,7 +175,6 @@ def dtypes(self) -> pandas.Series: @property def size(self) -> int: - """Returns the size of the Index.""" return self.shape[0] @property @@ -186,12 +185,7 @@ def empty(self) -> bool: @property @validations.requires_ordering() def is_monotonic_increasing(self) -> bool: - """ - Return a boolean if the values are equal or increasing. - Returns: - bool - """ return typing.cast( bool, self._block.is_monotonic_increasing(self._block.index_columns), @@ -200,12 +194,7 @@ def is_monotonic_increasing(self) -> bool: @property @validations.requires_ordering() def is_monotonic_decreasing(self) -> bool: - """ - Return a boolean if the values are equal or decreasing. - Returns: - bool - """ return typing.cast( bool, self._block.is_monotonic_decreasing(self._block.index_columns), From 771e08ba9d6eabc6ba8914111221e87ab1a4bc1c Mon Sep 17 00:00:00 2001 From: Arwa Date: Mon, 25 Nov 2024 10:04:33 -0600 Subject: [PATCH 4/7] fix doctest errors --- .../pandas/core/indexes/base.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/third_party/bigframes_vendored/pandas/core/indexes/base.py b/third_party/bigframes_vendored/pandas/core/indexes/base.py index d2ac96ad59..d23a8a44fb 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/base.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/base.py @@ -97,7 +97,7 @@ def size(self) -> int: >>> idx = bpd.Index([1, 2, 3]) >>> idx - 3 + Index([1, 2, 3], dtype='Int64') Returns: int: @@ -120,7 +120,7 @@ def is_monotonic_increasing(self) -> bool: >>> bpd.options.display.progress_bar = None >>> bpd.Index([1, 2, 3]).is_monotonic_increasing - True + np.True_ >>> bpd.Index([1, 2, 2]).is_monotonic_increasing True @@ -145,7 +145,7 @@ def is_monotonic_decreasing(self) -> bool: >>> bpd.options.display.progress_bar = None >>> bpd.Index([3, 2, 1]).is_monotonic_decreasing - True + np.True_ >>> bpd.Index([3, 2, 2]).is_monotonic_decreasing True @@ -173,15 +173,13 @@ def from_frame(cls, frame) -> Index: ... ['NJ', 'Temp'], ['NJ', 'Precip']], ... columns=['a', 'b']) >>> df - a b - 0 HI Temp - 1 HI Precip - 2 NJ Temp - 3 NJ Precip + a b + 0 HI Temp + 1 HI Precip + 2 NJ Temp + 3 NJ Precip 4 rows x 2 columns - [4 rows x 2 columns in total] - >>> bpd.MultiIndex.from_frame(df) Index([0, 1, 2, 3], dtype='Int64') From 3a07f255fa9384b3856585e39d0e79485bccc013 Mon Sep 17 00:00:00 2001 From: Arwa Date: Mon, 25 Nov 2024 11:05:28 -0600 Subject: [PATCH 5/7] fix doctest error --- .../pandas/core/indexes/base.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/third_party/bigframes_vendored/pandas/core/indexes/base.py b/third_party/bigframes_vendored/pandas/core/indexes/base.py index d23a8a44fb..459ab7c472 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/base.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/base.py @@ -123,7 +123,7 @@ def is_monotonic_increasing(self) -> bool: np.True_ >>> bpd.Index([1, 2, 2]).is_monotonic_increasing - True + np.True_ >>> bpd.Index([1, 3, 2]).is_monotonic_increasing False @@ -148,7 +148,7 @@ def is_monotonic_decreasing(self) -> bool: np.True_ >>> bpd.Index([3, 2, 2]).is_monotonic_decreasing - True + np.True_ >>> bpd.Index([3, 1, 2]).is_monotonic_decreasing False @@ -173,12 +173,13 @@ def from_frame(cls, frame) -> Index: ... ['NJ', 'Temp'], ['NJ', 'Precip']], ... columns=['a', 'b']) >>> df - a b - 0 HI Temp - 1 HI Precip - 2 NJ Temp - 3 NJ Precip - 4 rows x 2 columns + a b + 0 HI Temp + 1 HI Precip + 2 NJ Temp + 3 NJ Precip + + [4 rows x 2 columns] >>> bpd.MultiIndex.from_frame(df) Index([0, 1, 2, 3], dtype='Int64') From 21880cfa4597c886ac7ef2fd7d6b65ccc8ac69eb Mon Sep 17 00:00:00 2001 From: Arwa Date: Mon, 25 Nov 2024 11:49:43 -0600 Subject: [PATCH 6/7] fix doctest --- .../pandas/core/indexes/base.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/third_party/bigframes_vendored/pandas/core/indexes/base.py b/third_party/bigframes_vendored/pandas/core/indexes/base.py index 459ab7c472..d69a149603 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/base.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/base.py @@ -119,13 +119,13 @@ def is_monotonic_increasing(self) -> bool: >>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None - >>> bpd.Index([1, 2, 3]).is_monotonic_increasing - np.True_ + >>> bool(bpd.Index([1, 2, 3]).is_monotonic_increasing) + True - >>> bpd.Index([1, 2, 2]).is_monotonic_increasing - np.True_ + >>> bool(bpd.Index([1, 2, 2]).is_monotonic_increasing) + True - >>> bpd.Index([1, 3, 2]).is_monotonic_increasing + >>> bool(bpd.Index([1, 3, 2]).is_monotonic_increasing) False Returns: @@ -144,13 +144,13 @@ def is_monotonic_decreasing(self) -> bool: >>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None - >>> bpd.Index([3, 2, 1]).is_monotonic_decreasing - np.True_ + >>> bool(bpd.Index([3, 2, 1]).is_monotonic_decreasing) + True - >>> bpd.Index([3, 2, 2]).is_monotonic_decreasing - np.True_ + >>> bool(bpd.Index([3, 2, 2]).is_monotonic_decreasing) + True - >>> bpd.Index([3, 1, 2]).is_monotonic_decreasing + >>> bool(bpd.Index([3, 1, 2]).is_monotonic_decreasing) False Returns: @@ -178,7 +178,7 @@ def from_frame(cls, frame) -> Index: 1 HI Precip 2 NJ Temp 3 NJ Precip - + [4 rows x 2 columns] >>> bpd.MultiIndex.from_frame(df) From 7a0570e9c8bc892e0ccc976d4ef3d79284eb7855 Mon Sep 17 00:00:00 2001 From: Arwa Date: Wed, 27 Nov 2024 09:47:53 -0600 Subject: [PATCH 7/7] add name docstring --- .../pandas/core/indexes/base.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/third_party/bigframes_vendored/pandas/core/indexes/base.py b/third_party/bigframes_vendored/pandas/core/indexes/base.py index d69a149603..4550f800a2 100644 --- a/third_party/bigframes_vendored/pandas/core/indexes/base.py +++ b/third_party/bigframes_vendored/pandas/core/indexes/base.py @@ -24,6 +24,27 @@ class Index: a default session is used. """ + @property + def name(self): + """Returns Index name. + + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> idx = bpd.Index([1, 2, 3], name='x') + >>> idx + Index([1, 2, 3], dtype='Int64', name='x') + >>> idx.name + 'x' + + Returns: + blocks.Label: + Index or MultiIndex name + """ + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + @property def names(self): """Returns the names of the Index.