Skip to content

Commit c5f0835

Browse files
authored
add scalar.parent_dataframe (#333)
1 parent 01f6d94 commit c5f0835

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

spec/API_specification/dataframe_api/scalar_object.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if TYPE_CHECKING:
66
from typing_extensions import Self
77

8-
from dataframe_api.typing import AnyScalar, DType, Namespace
8+
from dataframe_api.typing import AnyScalar, DataFrame, DType, Namespace
99

1010
__all__ = ["Scalar"]
1111

@@ -24,8 +24,33 @@ class Scalar(Protocol):
2424
For example, if `column` is `Column` of dtype `Int64`, then
2525
`column.get_value(0)` will return a `Scalar` of dtype `Int64`
2626
(even if it is backed by a null value).
27+
28+
In binary operations, the comparand's parent DataFrame must be the same as
29+
`self`'s - else, the operation is unsupported and may vary across implementations.
2730
"""
2831

32+
@property
33+
def parent_dataframe(self) -> DataFrame | None:
34+
"""Return parent DataFrame, if present.
35+
36+
For example, if we have the following
37+
38+
.. code-block:: python
39+
40+
df: DataFrame
41+
scalar = df.col('a').mean()
42+
43+
then `scalar.parent_dataframe` should return `df`.
44+
45+
On the other hand, if we had:
46+
47+
.. code-block:: python
48+
49+
scalar = column_from_1d_array(...).mean()
50+
51+
then `scalar.parent_dataframe` should return `None`.
52+
"""
53+
2954
def __scalar_namespace__(self) -> Namespace:
3055
"""Return an object that has all the Dataframe Standard API functions on it.
3156

0 commit comments

Comments
 (0)