55if 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