@@ -31,11 +31,36 @@ builtin types to CPU. In the above example, the `.mean()` call returns a
31
31
scalar object which duck types with ` float ` . This means that it should (a) have
32
32
the same semantics as a builtin ` float ` when used within a library, and (b)
33
33
support usage as a ` float ` outside of the library (i.e., implement
34
- ` __float__ ` ). Duck typing is usually not perfect, for example ` isinstance `
34
+ ` __float__ ` and other methods - see below ). Duck typing is usually not perfect, for example ` isinstance `
35
35
usage on the float-like duck type will behave differently. Such explicit "type
36
36
of object" checks don't have to be supported.
37
37
38
38
The following design rule applies everywhere builtin Python types are used
39
39
within this API standard: _ where a Python builtin type is specified, an
40
40
implementation may always replace it by an equivalent library-specific type
41
41
that duck types with the Python builtin type._
42
+
43
+ ## Required methods
44
+
45
+ A ducktyped float scalar is required to implement all the methods which ` float ` implements.
46
+
47
+ For example, if a library implements ` FancyFloat ` and ` FancyBool ` scalars,
48
+ then the following should all be supported:
49
+ ``` python
50
+ df: DataFrame
51
+ column_1: Column = df.col(' a' )
52
+ column_2: Column = df.col(' b' )
53
+
54
+ scalar: FancyFloat = column_1.std()
55
+ result_1: Column = column_2 - column_1.std()
56
+ result_2: FancyBool = column_2.std() > column_1.std()
57
+ ```
58
+ The following, however, may raise, dependening on the
59
+ implementation:
60
+ ``` python
61
+ df: DataFrame
62
+ column = df.col(' a' )
63
+
64
+ if column.std() > 0 : # this line may raise!
65
+ print (' std is positive' )
66
+ ```
0 commit comments