5
5
if TYPE_CHECKING :
6
6
from typing_extensions import Self
7
7
8
- from dataframe_api .typing import AnyScalar , DType , Namespace
8
+ from dataframe_api .typing import AnyScalar , DataFrame , DType , Namespace
9
9
10
10
__all__ = ["Scalar" ]
11
11
@@ -24,8 +24,33 @@ class Scalar(Protocol):
24
24
For example, if `column` is `Column` of dtype `Int64`, then
25
25
`column.get_value(0)` will return a `Scalar` of dtype `Int64`
26
26
(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.
27
30
"""
28
31
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
+
29
54
def __scalar_namespace__ (self ) -> Namespace :
30
55
"""Return an object that has all the Dataframe Standard API functions on it.
31
56
0 commit comments