Skip to content

Commit 161c61f

Browse files
IndexSeekcpcloud
authored andcommitted
docs(examples): add std, var, corr, and cov usage examples
1 parent c545825 commit 161c61f

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

ibis/expr/types/numeric.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,33 @@ def std(
786786
-------
787787
NumericScalar
788788
Standard deviation of `arg`
789+
790+
Examples
791+
--------
792+
>>> import ibis
793+
>>> ibis.options.interactive = True
794+
>>> t = ibis.memtable(
795+
... {
796+
... "values": [1, 3, 3, 4, 5, 7],
797+
... }
798+
... )
799+
>>> t.values.std()
800+
┌──────────┐
801+
│ 2.041241 │
802+
└──────────┘
803+
>>> t.mutate(std_col=t.values.std())
804+
┏━━━━━━━━┳━━━━━━━━━━┓
805+
┃ values ┃ std_col ┃
806+
┡━━━━━━━━╇━━━━━━━━━━┩
807+
│ int64 │ float64 │
808+
├────────┼──────────┤
809+
│ 1 │ 2.041241 │
810+
│ 3 │ 2.041241 │
811+
│ 3 │ 2.041241 │
812+
│ 4 │ 2.041241 │
813+
│ 5 │ 2.041241 │
814+
│ 7 │ 2.041241 │
815+
└────────┴──────────┘
789816
"""
790817
return ops.StandardDev(
791818
self, how=how, where=self._bind_to_parent_table(where)
@@ -809,6 +836,33 @@ def var(
809836
-------
810837
NumericScalar
811838
Standard deviation of `arg`
839+
840+
Examples
841+
--------
842+
>>> import ibis
843+
>>> ibis.options.interactive = True
844+
>>> t = ibis.memtable(
845+
... {
846+
... "values": [1, 3, 3, 4, 5, 7],
847+
... }
848+
... )
849+
>>> t.values.var()
850+
┌──────────┐
851+
│ 4.166667 │
852+
└──────────┘
853+
>>> t.mutate(var_col=t.values.var())
854+
┏━━━━━━━━┳━━━━━━━━━━┓
855+
┃ values ┃ var_col ┃
856+
┡━━━━━━━━╇━━━━━━━━━━┩
857+
│ int64 │ float64 │
858+
├────────┼──────────┤
859+
│ 1 │ 4.166667 │
860+
│ 3 │ 4.166667 │
861+
│ 3 │ 4.166667 │
862+
│ 4 │ 4.166667 │
863+
│ 5 │ 4.166667 │
864+
│ 7 │ 4.166667 │
865+
└────────┴──────────┘
812866
"""
813867
return ops.Variance(
814868
self, how=how, where=self._bind_to_parent_table(where)
@@ -835,6 +889,34 @@ def corr(
835889
-------
836890
NumericScalar
837891
The correlation of `left` and `right`
892+
893+
Examples
894+
--------
895+
>>> import ibis
896+
>>> ibis.options.interactive = True
897+
>>> t = ibis.memtable(
898+
... {
899+
... "left": [1, 3, 3, 4, 5, 7],
900+
... "right": [7, 5, 4, 3, 3, 1],
901+
... }
902+
... )
903+
>>> t.left.corr(t.right, how="pop")
904+
┌────────┐
905+
│ -0.968 │
906+
└────────┘
907+
>>> t.mutate(corr_col=t.left.corr(t.right, how="pop"))
908+
┏━━━━━━━┳━━━━━━━┳━━━━━━━━━━┓
909+
┃ left ┃ right ┃ corr_col ┃
910+
┡━━━━━━━╇━━━━━━━╇━━━━━━━━━━┩
911+
│ int64 │ int64 │ float64 │
912+
├───────┼───────┼──────────┤
913+
│ 1 │ 7 │ -0.968 │
914+
│ 3 │ 5 │ -0.968 │
915+
│ 3 │ 4 │ -0.968 │
916+
│ 4 │ 3 │ -0.968 │
917+
│ 5 │ 3 │ -0.968 │
918+
│ 7 │ 1 │ -0.968 │
919+
└───────┴───────┴──────────┘
838920
"""
839921
return ops.Correlation(
840922
self,
@@ -864,6 +946,38 @@ def cov(
864946
-------
865947
NumericScalar
866948
The covariance of `self` and `right`
949+
950+
Examples
951+
--------
952+
>>> import ibis
953+
>>> ibis.options.interactive = True
954+
>>> t = ibis.memtable(
955+
... {
956+
... "left": [1, 3, 3, 4, 5, 7],
957+
... "right": [7, 5, 4, 3, 3, 1],
958+
... }
959+
... )
960+
>>> t.left.cov(t.right)
961+
┌───────────┐
962+
│ -4.033333 │
963+
└───────────┘
964+
>>> t.left.cov(t.right, how="pop")
965+
┌───────────┐
966+
│ -3.361111 │
967+
└───────────┘
968+
>>> t.mutate(cov_col=t.left.cov(t.right, how="pop"))
969+
┏━━━━━━━┳━━━━━━━┳━━━━━━━━━━━┓
970+
┃ left ┃ right ┃ cov_col ┃
971+
┡━━━━━━━╇━━━━━━━╇━━━━━━━━━━━┩
972+
│ int64 │ int64 │ float64 │
973+
├───────┼───────┼───────────┤
974+
│ 1 │ 7 │ -3.361111 │
975+
│ 3 │ 5 │ -3.361111 │
976+
│ 3 │ 4 │ -3.361111 │
977+
│ 4 │ 3 │ -3.361111 │
978+
│ 5 │ 3 │ -3.361111 │
979+
│ 7 │ 1 │ -3.361111 │
980+
└───────┴───────┴───────────┘
867981
"""
868982
return ops.Covariance(
869983
self,

0 commit comments

Comments
 (0)