| 2319 | return tuple(self.mins) + (self.maxes[-1],) |
| 2320 | |
| 2321 | def _layer(self): |
| 2322 | non_empties = [i for i, length in enumerate(self.lens) if length != 0] |
| 2323 | # If all empty, collapse into one partition |
| 2324 | if len(non_empties) == 0: |
| 2325 | return {(self._name, 0): (self.frame._name, 0)} |
| 2326 | |
| 2327 | # drop empty partitions by mapping each partition in a new graph to a particular |
| 2328 | # partition on the old graph. |
| 2329 | dsk = { |
| 2330 | (self._name, i): (self.frame._name, div) |
| 2331 | for i, div in enumerate(non_empties) |
| 2332 | } |
| 2333 | ddf_keys = list(dsk.values()) |
| 2334 | |
| 2335 | overlap = [ |
| 2336 | i for i in range(1, len(self.mins)) if self.mins[i] >= self.maxes[i - 1] |
| 2337 | ] |
| 2338 | divisions = self.divisions |
| 2339 | |
| 2340 | frames = [] |
| 2341 | for i in overlap: |
| 2342 | # `frames` is a list of data from previous partitions that we may want to |
| 2343 | # move to partition i. Here, we add "overlap" from the previous partition |
| 2344 | # (i-1) to this list. |
| 2345 | frames.append((get_overlap, ddf_keys[i - 1], divisions[i])) |
| 2346 | |
| 2347 | # Make sure that any data added from partition i-1 to `frames` is removed |
| 2348 | # from partition i-1. |
| 2349 | dsk[(self._name, i - 1)] = ( |
| 2350 | drop_overlap, |
| 2351 | dsk[(self._name, i - 1)], |
| 2352 | divisions[i], |
| 2353 | ) |
| 2354 | |
| 2355 | # We do not want to move "overlap" from the previous partition (i-1) into |
| 2356 | # this partition (i) if the data from this partition will need to be moved |
| 2357 | # to the next partition (i+1) anyway. If we concatenate data too early, |
| 2358 | # we may lose rows (https://github.com/dask/dask/issues/6972). |
| 2359 | if divisions[i] == divisions[i + 1] and i + 1 in overlap: |
| 2360 | continue |
| 2361 | |
| 2362 | frames.append(ddf_keys[i]) |
| 2363 | dsk[(self._name, i)] = (methods.concat, frames) |
| 2364 | frames = [] |
| 2365 | return dsk |
| 2366 | |
| 2367 | |
| 2368 | class Lengths(Expr): |