pyochain 0.5.1__py3-none-any.whl → 0.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyochain might be problematic. Click here for more details.

@@ -31,7 +31,6 @@ class BasePartitions[T](IterWrapper[T]):
31
31
 
32
32
  Args:
33
33
  length: The length of each window.
34
-
35
34
  ```python
36
35
  >>> import pyochain as pc
37
36
  >>> pc.Iter.from_([1, 2, 3, 4]).windows(2).into(list)
@@ -47,7 +46,7 @@ class BasePartitions[T](IterWrapper[T]):
47
46
 
48
47
  ```
49
48
  """
50
- return self.apply(partial(cz.itertoolz.sliding_window, length))
49
+ return self._lazy(partial(cz.itertoolz.sliding_window, length))
51
50
 
52
51
  @overload
53
52
  def partition(self, n: Literal[1], pad: None = None) -> Iter[tuple[T]]: ...
@@ -70,7 +69,6 @@ class BasePartitions[T](IterWrapper[T]):
70
69
  Args:
71
70
  n: Length of each partition.
72
71
  pad: Value to pad the last partition if needed.
73
-
74
72
  ```python
75
73
  >>> import pyochain as pc
76
74
  >>> pc.Iter.from_([1, 2, 3, 4]).partition(2).into(list)
@@ -85,7 +83,7 @@ class BasePartitions[T](IterWrapper[T]):
85
83
  ```
86
84
  """
87
85
 
88
- return self.apply(partial(cz.itertoolz.partition, n, pad=pad))
86
+ return self._lazy(partial(cz.itertoolz.partition, n, pad=pad))
89
87
 
90
88
  def partition_all(self, n: int) -> Iter[tuple[T, ...]]:
91
89
  """
@@ -93,7 +91,6 @@ class BasePartitions[T](IterWrapper[T]):
93
91
 
94
92
  Args:
95
93
  n: Maximum length of each partition.
96
-
97
94
  The final tuple may be shorter to accommodate extra elements.
98
95
  ```python
99
96
  >>> import pyochain as pc
@@ -104,17 +101,17 @@ class BasePartitions[T](IterWrapper[T]):
104
101
 
105
102
  ```
106
103
  """
107
- return self.apply(partial(cz.itertoolz.partition_all, n))
104
+ return self._lazy(partial(cz.itertoolz.partition_all, n))
108
105
 
109
106
  def partition_by(self, predicate: Callable[[T], bool]) -> Iter[tuple[T, ...]]:
110
107
  """
111
108
  Partition the `iterable` into a sequence of `tuples` according to a predicate function.
112
109
 
113
- Args:
114
- predicate: Function to determine partition boundaries.
115
-
116
110
  Every time the output of `predicate` changes, a new `tuple` is started,
117
111
  and subsequent items are collected into that `tuple`.
112
+
113
+ Args:
114
+ predicate: Function to determine partition boundaries.
118
115
  ```python
119
116
  >>> import pyochain as pc
120
117
  >>> pc.Iter.from_("I have space").partition_by(lambda c: c == " ").into(list)
@@ -126,18 +123,18 @@ class BasePartitions[T](IterWrapper[T]):
126
123
 
127
124
  ```
128
125
  """
129
- return self.apply(partial(cz.recipes.partitionby, predicate))
126
+ return self._lazy(partial(cz.recipes.partitionby, predicate))
130
127
 
131
128
  def batch(self, n: int) -> Iter[tuple[T, ...]]:
132
129
  """
133
130
  Batch elements into tuples of length n and return a new Iter.
134
131
 
135
- Args:
136
- n: Number of elements in each batch.
137
-
138
132
  - The last batch may be shorter than n.
139
133
  - The data is consumed lazily, just enough to fill a batch.
140
134
  - The result is yielded as soon as a batch is full or when the input iterable is exhausted.
135
+
136
+ Args:
137
+ n: Number of elements in each batch.
141
138
  ```python
142
139
  >>> import pyochain as pc
143
140
  >>> pc.Iter.from_("ABCDEFG").batch(3).into(list)
@@ -145,4 +142,4 @@ class BasePartitions[T](IterWrapper[T]):
145
142
 
146
143
  ```
147
144
  """
148
- return self.apply(itertools.batched, n)
145
+ return self._lazy(itertools.batched, n)
@@ -46,7 +46,7 @@ class BaseProcess[T](IterWrapper[T]):
46
46
 
47
47
  ```
48
48
  """
49
- return self.apply(itertools.cycle)
49
+ return self._lazy(itertools.cycle)
50
50
 
51
51
  def interpose(self, element: T) -> Iter[T]:
52
52
  """
@@ -54,7 +54,6 @@ class BaseProcess[T](IterWrapper[T]):
54
54
 
55
55
  Args:
56
56
  element: The element to interpose between items.
57
-
58
57
  Example:
59
58
  ```python
60
59
  >>> import pyochain as pc
@@ -63,7 +62,7 @@ class BaseProcess[T](IterWrapper[T]):
63
62
 
64
63
  ```
65
64
  """
66
- return self.apply(partial(cz.itertoolz.interpose, element))
65
+ return self._lazy(partial(cz.itertoolz.interpose, element))
67
66
 
68
67
  def random_sample(
69
68
  self, probability: float, state: Random | int | None = None
@@ -71,15 +70,15 @@ class BaseProcess[T](IterWrapper[T]):
71
70
  """
72
71
  Return elements from a sequence with probability of prob.
73
72
 
74
- Args:
75
- probability: The probability of including each element.
76
- state: Random state or seed for deterministic sampling.
77
-
78
73
  Returns a lazy iterator of random items from seq.
79
74
 
80
75
  random_sample considers each item independently and without replacement.
81
76
 
82
77
  See below how the first time it returned 13 items and the next time it returned 6 items.
78
+
79
+ Args:
80
+ probability: The probability of including each element.
81
+ state: Random state or seed for deterministic sampling.
83
82
  ```python
84
83
  >>> import pyochain as pc
85
84
  >>> data = pc.Seq(list(range(100)))
@@ -108,7 +107,7 @@ class BaseProcess[T](IterWrapper[T]):
108
107
  ```
109
108
  """
110
109
 
111
- return self.apply(
110
+ return self._lazy(
112
111
  partial(cz.itertoolz.random_sample, probability, random_state=state)
113
112
  )
114
113
 
@@ -118,7 +117,6 @@ class BaseProcess[T](IterWrapper[T]):
118
117
 
119
118
  Args:
120
119
  func: A binary function to apply cumulatively.
121
-
122
120
  ```python
123
121
  >>> import pyochain as pc
124
122
  >>> pc.Iter.from_([1, 2, 3]).accumulate(lambda a, b: a + b).into(list)
@@ -126,7 +124,7 @@ class BaseProcess[T](IterWrapper[T]):
126
124
 
127
125
  ```
128
126
  """
129
- return self.apply(partial(cz.itertoolz.accumulate, func))
127
+ return self._lazy(partial(cz.itertoolz.accumulate, func))
130
128
 
131
129
  def insert_left(self, value: T) -> Iter[T]:
132
130
  """
@@ -134,7 +132,6 @@ class BaseProcess[T](IterWrapper[T]):
134
132
 
135
133
  Args:
136
134
  value: The value to prepend.
137
-
138
135
  ```python
139
136
  >>> import pyochain as pc
140
137
  >>> pc.Iter.from_([2, 3]).insert_left(1).into(list)
@@ -142,7 +139,7 @@ class BaseProcess[T](IterWrapper[T]):
142
139
 
143
140
  ```
144
141
  """
145
- return self.apply(partial(cz.itertoolz.cons, value))
142
+ return self._lazy(partial(cz.itertoolz.cons, value))
146
143
 
147
144
  def peekn(self, n: int) -> Iter[T]:
148
145
  """
@@ -150,7 +147,6 @@ class BaseProcess[T](IterWrapper[T]):
150
147
 
151
148
  Args:
152
149
  n: Number of items to peek.
153
-
154
150
  ```python
155
151
  >>> import pyochain as pc
156
152
  >>> pc.Iter.from_([1, 2, 3]).peekn(2).into(list)
@@ -165,7 +161,7 @@ class BaseProcess[T](IterWrapper[T]):
165
161
  print(f"Peeked {n} values: {peeked.value}")
166
162
  return peeked.sequence
167
163
 
168
- return self.apply(_peekn)
164
+ return self._lazy(_peekn)
169
165
 
170
166
  def peek(self) -> Iter[T]:
171
167
  """
@@ -184,7 +180,7 @@ class BaseProcess[T](IterWrapper[T]):
184
180
  print(f"Peeked value: {peeked.value}")
185
181
  return peeked.sequence
186
182
 
187
- return self.apply(_peek)
183
+ return self._lazy(_peek)
188
184
 
189
185
  def merge_sorted(
190
186
  self, *others: Iterable[T], sort_on: Callable[[T], Any] | None = None
@@ -195,7 +191,6 @@ class BaseProcess[T](IterWrapper[T]):
195
191
  Args:
196
192
  others: Other sorted iterables to merge.
197
193
  sort_on: Optional key function for sorting.
198
-
199
194
  ```python
200
195
  >>> import pyochain as pc
201
196
  >>> pc.Iter.from_([1, 3]).merge_sorted([2, 4]).into(list)
@@ -203,7 +198,7 @@ class BaseProcess[T](IterWrapper[T]):
203
198
 
204
199
  ```
205
200
  """
206
- return self.apply(cz.itertoolz.merge_sorted, *others, key=sort_on)
201
+ return self._lazy(cz.itertoolz.merge_sorted, *others, key=sort_on)
207
202
 
208
203
  def interleave(self, *others: Iterable[T]) -> Iter[T]:
209
204
  """
@@ -211,7 +206,6 @@ class BaseProcess[T](IterWrapper[T]):
211
206
 
212
207
  Args:
213
208
  others: Other iterables to interleave.
214
-
215
209
  ```python
216
210
  >>> import pyochain as pc
217
211
  >>> pc.Iter.from_([1, 2]).interleave([3, 4]).into(list)
@@ -223,18 +217,18 @@ class BaseProcess[T](IterWrapper[T]):
223
217
  def _interleave(data: Iterable[T]) -> Iterator[T]:
224
218
  return cz.itertoolz.interleave((data, *others))
225
219
 
226
- return self.apply(_interleave)
220
+ return self._lazy(_interleave)
227
221
 
228
222
  def chain(self, *others: Iterable[T]) -> Iter[T]:
229
223
  """
230
224
  Concatenate zero or more iterables, any of which may be infinite.
231
225
 
232
- Args:
233
- others: Other iterables to concatenate.
234
-
235
226
  An infinite sequence will prevent the rest of the arguments from being included.
236
227
 
237
228
  We use chain.from_iterable rather than chain(*seqs) so that seqs can be a generator.
229
+
230
+ Args:
231
+ others: Other iterables to concatenate.
238
232
  ```python
239
233
  >>> import pyochain as pc
240
234
  >>> pc.Iter.from_([1, 2]).chain([3, 4], [5]).into(list)
@@ -244,9 +238,9 @@ class BaseProcess[T](IterWrapper[T]):
244
238
  """
245
239
 
246
240
  def _chain(data: Iterable[T]) -> Iterator[T]:
247
- return itertools.chain.from_iterable((data, *others))
241
+ return cz.itertoolz.concat((data, *others))
248
242
 
249
- return self.apply(_chain)
243
+ return self._lazy(_chain)
250
244
 
251
245
  def elements(self) -> Iter[T]:
252
246
  """
@@ -275,7 +269,7 @@ class BaseProcess[T](IterWrapper[T]):
275
269
  def _elements(data: Iterable[T]) -> Iterator[T]:
276
270
  return Counter(data).elements()
277
271
 
278
- return self.apply(_elements)
272
+ return self._lazy(_elements)
279
273
 
280
274
  def reverse(self) -> Iter[T]:
281
275
  """
@@ -296,7 +290,7 @@ class BaseProcess[T](IterWrapper[T]):
296
290
  def _reverse(data: Iterable[T]) -> Iterator[T]:
297
291
  return reversed(list(data))
298
292
 
299
- return self.apply(_reverse)
293
+ return self._lazy(_reverse)
300
294
 
301
295
  def is_strictly_n(
302
296
  self,
@@ -307,14 +301,14 @@ class BaseProcess[T](IterWrapper[T]):
307
301
  """
308
302
  Validate that *iterable* has exactly *n* items and return them if it does.
309
303
 
304
+ If it has fewer than *n* items, call function *too_short* with the actual number of items.
305
+
306
+ If it has more than *n* items, call function *too_long* with the number `n + 1`.
307
+
310
308
  Args:
311
309
  n: The exact number of items expected.
312
310
  too_short: Function to call if there are too few items.
313
311
  too_long: Function to call if there are too many items.
314
-
315
- If it has fewer than *n* items, call function *too_short* with the actual number of items.
316
-
317
- If it has more than *n* items, call function *too_long* with the number `n + 1`.
318
312
  ```python
319
313
  >>> import pyochain as pc
320
314
  >>> iterable = ["a", "b", "c", "d"]
@@ -381,4 +375,4 @@ class BaseProcess[T](IterWrapper[T]):
381
375
  too_long(n + 1)
382
376
  return
383
377
 
384
- return self.apply(strictly_n_)
378
+ return self._lazy(strictly_n_)
@@ -18,7 +18,6 @@ class BaseRolling[T](IterWrapper[T]):
18
18
 
19
19
  Args:
20
20
  window_size: Size of the rolling window.
21
-
22
21
  ```python
23
22
  >>> import pyochain as pc
24
23
  >>> pc.Iter.from_([1, 2, 3, 4, 5]).rolling_mean(3).into(list)
@@ -26,7 +25,7 @@ class BaseRolling[T](IterWrapper[T]):
26
25
 
27
26
  ```
28
27
  """
29
- return self.apply(rolling.Mean, window_size)
28
+ return self._lazy(rolling.Mean, window_size)
30
29
 
31
30
  def rolling_median(self, window_size: int) -> Iter[T]:
32
31
  """
@@ -34,7 +33,6 @@ class BaseRolling[T](IterWrapper[T]):
34
33
 
35
34
  Args:
36
35
  window_size: Size of the rolling window.
37
-
38
36
  ```python
39
37
  >>> import pyochain as pc
40
38
  >>> pc.Iter.from_([1, 3, 2, 5, 4]).rolling_median(3).into(list)
@@ -42,16 +40,16 @@ class BaseRolling[T](IterWrapper[T]):
42
40
 
43
41
  ```
44
42
  """
45
- return self.apply(rolling.Median, window_size)
43
+ return self._lazy(rolling.Median, window_size)
46
44
 
47
45
  def rolling_sum(self, window_size: int) -> Iter[T]:
48
46
  """
49
47
  Compute the rolling sum.
50
48
 
49
+ Will return integers if the input is integers, floats if the input is floats or mixed.
50
+
51
51
  Args:
52
52
  window_size: Size of the rolling window.
53
-
54
- Will return integers if the input is integers, floats if the input is floats or mixed.
55
53
  ```python
56
54
  >>> import pyochain as pc
57
55
  >>> pc.Iter.from_([1.0, 2, 3, 4, 5]).rolling_sum(3).into(list)
@@ -59,7 +57,7 @@ class BaseRolling[T](IterWrapper[T]):
59
57
 
60
58
  ```
61
59
  """
62
- return self.apply(rolling.Sum, window_size)
60
+ return self._lazy(rolling.Sum, window_size)
63
61
 
64
62
  def rolling_min(self, window_size: int) -> Iter[T]:
65
63
  """
@@ -74,7 +72,7 @@ class BaseRolling[T](IterWrapper[T]):
74
72
 
75
73
  ```
76
74
  """
77
- return self.apply(rolling.Min, window_size)
75
+ return self._lazy(rolling.Min, window_size)
78
76
 
79
77
  def rolling_max(self, window_size: int) -> Iter[T]:
80
78
  """
@@ -89,7 +87,7 @@ class BaseRolling[T](IterWrapper[T]):
89
87
 
90
88
  ```
91
89
  """
92
- return self.apply(rolling.Max, window_size)
90
+ return self._lazy(rolling.Max, window_size)
93
91
 
94
92
  def rolling_var(self, window_size: int) -> Iter[float]:
95
93
  """
@@ -104,7 +102,7 @@ class BaseRolling[T](IterWrapper[T]):
104
102
 
105
103
  ```
106
104
  """
107
- return self.apply(rolling.Var, window_size)
105
+ return self._lazy(rolling.Var, window_size)
108
106
 
109
107
  def rolling_std(self, window_size: int) -> Iter[float]:
110
108
  """
@@ -119,16 +117,14 @@ class BaseRolling[T](IterWrapper[T]):
119
117
 
120
118
  ```
121
119
  """
122
- return self.apply(rolling.Std, window_size)
120
+ return self._lazy(rolling.Std, window_size)
123
121
 
124
122
  def rolling_kurtosis(self, window_size: int) -> Iter[float]:
125
123
  """
126
124
  Compute the rolling kurtosis.
127
125
 
128
126
  Args:
129
- window_size: Size of the rolling window.
130
-
131
- The windows must have at least 4 observations.
127
+ window_size: Size of the rolling window. Must be at least 4.
132
128
  ```python
133
129
  >>> import pyochain as pc
134
130
  >>> pc.Iter.from_([1, 2, 4, 1, 4]).rolling_kurtosis(4).into(list)
@@ -136,16 +132,14 @@ class BaseRolling[T](IterWrapper[T]):
136
132
 
137
133
  ```
138
134
  """
139
- return self.apply(rolling.Kurtosis, window_size)
135
+ return self._lazy(rolling.Kurtosis, window_size)
140
136
 
141
137
  def rolling_skew(self, window_size: int) -> Iter[float]:
142
138
  """
143
139
  Compute the rolling skewness.
144
140
 
145
141
  Args:
146
- window_size: Size of the rolling window.
147
-
148
- The windows must have at least 3 observations.
142
+ window_size: Size of the rolling window. Must be at least 3.
149
143
  ```python
150
144
  >>> import pyochain as pc
151
145
  >>> pc.Iter.from_([1, 2, 4, 1, 4]).rolling_skew(3).round(2).into(list)
@@ -153,7 +147,7 @@ class BaseRolling[T](IterWrapper[T]):
153
147
 
154
148
  ```
155
149
  """
156
- return self.apply(rolling.Skew, window_size)
150
+ return self._lazy(rolling.Skew, window_size)
157
151
 
158
152
  def rolling_all(self, window_size: int) -> Iter[bool]:
159
153
  """
@@ -168,7 +162,7 @@ class BaseRolling[T](IterWrapper[T]):
168
162
 
169
163
  ```
170
164
  """
171
- return self.apply(rolling.All, window_size)
165
+ return self._lazy(rolling.All, window_size)
172
166
 
173
167
  def rolling_any(self, window_size: int) -> Iter[bool]:
174
168
  """
@@ -183,7 +177,7 @@ class BaseRolling[T](IterWrapper[T]):
183
177
 
184
178
  ```
185
179
  """
186
- return self.apply(rolling.Any, window_size)
180
+ return self._lazy(rolling.Any, window_size)
187
181
 
188
182
  def rolling_product(self, window_size: int) -> Iter[float]:
189
183
  """
@@ -198,7 +192,7 @@ class BaseRolling[T](IterWrapper[T]):
198
192
 
199
193
  ```
200
194
  """
201
- return self.apply(rolling.Product, window_size)
195
+ return self._lazy(rolling.Product, window_size)
202
196
 
203
197
  def rolling_apply[R](
204
198
  self, func: Callable[[Iterable[T]], R], window_size: int
@@ -206,11 +200,11 @@ class BaseRolling[T](IterWrapper[T]):
206
200
  """
207
201
  Apply a custom function to each rolling window.
208
202
 
203
+ The function should accept an iterable and return a single value.
204
+
209
205
  Args:
210
206
  func: Function to apply to each rolling window.
211
207
  window_size: Size of the rolling window.
212
-
213
- The function should accept an iterable and return a single value.
214
208
  ```python
215
209
  >>> import pyochain as pc
216
210
  >>> def range_func(window):
@@ -220,7 +214,7 @@ class BaseRolling[T](IterWrapper[T]):
220
214
 
221
215
  ```
222
216
  """
223
- return self.apply(rolling.Apply, window_size, "fixed", func)
217
+ return self._lazy(rolling.Apply, window_size, "fixed", func)
224
218
 
225
219
  def rolling_apply_pairwise[R](
226
220
  self, other: Iterable[T], func: Callable[[T, T], R], window_size: int
@@ -228,12 +222,12 @@ class BaseRolling[T](IterWrapper[T]):
228
222
  """
229
223
  Apply a custom pairwise function to each rolling window of size 2.
230
224
 
225
+ The function should accept two arguments and return a single value.
226
+
231
227
  Args:
232
228
  other: Second iterable to apply the pairwise function.
233
229
  func: Function to apply to each pair of elements.
234
230
  window_size: Size of the rolling window.
235
-
236
- The function should accept two arguments and return a single value.
237
231
  ```python
238
232
  >>> import pyochain as pc
239
233
  >>> from statistics import correlation as corr
@@ -244,4 +238,4 @@ class BaseRolling[T](IterWrapper[T]):
244
238
 
245
239
  ```
246
240
  """
247
- return self.apply(rolling.ApplyPairwise, other, window_size, func)
241
+ return self._lazy(rolling.ApplyPairwise, other, window_size, func)