@@ -39,14 +39,46 @@ def __init__(
3939 """
4040 self .raw_type = PetInputDataType .UNKNOWN
4141 self .ds = self .from_arrlike (arraylike , dummy_varname , dimnames )
42- self .return_raw_result = False
42+ self .return_raw_result = True
4343
44- def with_return_raw_result (self , return_raw_result = bool ):
44+ def with_return_raw_result (self , return_raw_result : bool = True ):
4545 """
4646 Optionally set this to return raw array from `map_each_var`
4747
48- NOTE: this is a special purpose function. It is currently UNUSED, but
49- may be useful in some rare circumstances where
48+ NOTE: this is a special purpose function. It is useful when multiple operations that take in
49+ PetDataArrayLike are chained. In which case self.return_raw_result = False will have some
50+ slight performance benefit, otherwise you'd have to do:
51+
52+ ```
53+ pd1 = PetDataset(arr)
54+ res1 = pd1.map_each_var(fn1)
55+ pd2 = PetDataset(res1) # each of this call incurs a overhead.
56+ res2 = pd2.map_each_var(fn2)
57+ ```
58+
59+ Instead, setting `with_return_raw_result(False)` we can chain methods:
60+
61+ ```
62+ pet_ds = PetDataset(arr)
63+ # no over head since the return type of each method is already a PetDataset
64+ result = pet_ds.map_each_var(fn1).map_each_var(fn2)...
65+ ```
66+
67+ Finally we can set:
68+
69+ ```
70+ raw_result =
71+ pet_ds.map_each_var(fn1)
72+ .map_each_var(fn2)
73+ ...
74+ .with_return_raw_result()
75+ .map_each_var(final_fn)
76+ ```
77+
78+ if we explicitly need the raw result at the end.
79+
80+ The default (True) is always to return the original array type. This would be the case for
81+ most one-off computations.
5082 """
5183 self .return_raw_result = return_raw_result
5284
0 commit comments