Skip to content

Add Scalar.parent_dataframe #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2023
Merged
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
27 changes: 26 additions & 1 deletion spec/API_specification/dataframe_api/scalar_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if TYPE_CHECKING:
from typing_extensions import Self

from dataframe_api.typing import AnyScalar, DType, Namespace
from dataframe_api.typing import AnyScalar, DataFrame, DType, Namespace

__all__ = ["Scalar"]

Expand All @@ -24,8 +24,33 @@ class Scalar(Protocol):
For example, if `column` is `Column` of dtype `Int64`, then
`column.get_value(0)` will return a `Scalar` of dtype `Int64`
(even if it is backed by a null value).

In binary operations, the comparand's parent DataFrame must be the same as
`self`'s - else, the operation is unsupported and may vary across implementations.
"""

@property
def parent_dataframe(self) -> DataFrame | None:
"""Return parent DataFrame, if present.

For example, if we have the following

.. code-block:: python

df: DataFrame
scalar = df.col('a').mean()

then `scalar.parent_dataframe` should return `df`.

On the other hand, if we had:

.. code-block:: python

scalar = column_from_1d_array(...).mean()

then `scalar.parent_dataframe` should return `None`.
"""

def __scalar_namespace__(self) -> Namespace:
"""Return an object that has all the Dataframe Standard API functions on it.

Expand Down