Skip to content

Commit 90f1645

Browse files
committed
note what may raise
1 parent c4ab5b4 commit 90f1645

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

spec/design_topics/python_builtin_types.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,36 @@ builtin types to CPU. In the above example, the `.mean()` call returns a
3131
scalar object which duck types with `float`. This means that it should (a) have
3232
the same semantics as a builtin `float` when used within a library, and (b)
3333
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`
3535
usage on the float-like duck type will behave differently. Such explicit "type
3636
of object" checks don't have to be supported.
3737

3838
The following design rule applies everywhere builtin Python types are used
3939
within this API standard: _where a Python builtin type is specified, an
4040
implementation may always replace it by an equivalent library-specific type
4141
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

Comments
 (0)