Repartition a collection Exactly one of `divisions`, `npartitions` or `partition_size` should be specified. A ``ValueError`` will be raised when that is not the case. Parameters ---------- divisions : list, optional The "dividing lines" used to s
(
self,
divisions: tuple | None = None,
npartitions: int | None = None,
partition_size: str | None = None,
freq=None,
force: bool = False,
)
| 1286 | ) |
| 1287 | |
| 1288 | def repartition( |
| 1289 | self, |
| 1290 | divisions: tuple | None = None, |
| 1291 | npartitions: int | None = None, |
| 1292 | partition_size: str | None = None, |
| 1293 | freq=None, |
| 1294 | force: bool = False, |
| 1295 | ): |
| 1296 | """Repartition a collection |
| 1297 | |
| 1298 | Exactly one of `divisions`, `npartitions` or `partition_size` should be |
| 1299 | specified. A ``ValueError`` will be raised when that is not the case. |
| 1300 | |
| 1301 | Parameters |
| 1302 | ---------- |
| 1303 | divisions : list, optional |
| 1304 | The "dividing lines" used to split the dataframe into partitions. |
| 1305 | For ``divisions=[0, 10, 50, 100]``, there would be three output partitions, |
| 1306 | where the new index contained [0, 10), [10, 50), and [50, 100), respectively. |
| 1307 | See https://docs.dask.org/en/latest/dataframe-design.html#partitions. |
| 1308 | npartitions : int, Callable, optional |
| 1309 | Approximate number of partitions of output. The number of |
| 1310 | partitions used may be slightly lower than npartitions depending |
| 1311 | on data distribution, but will never be higher. |
| 1312 | The Callable gets the number of partitions of the input as an argument |
| 1313 | and should return an int. |
| 1314 | partition_size : str, optional |
| 1315 | Max number of bytes of memory for each partition. Use numbers or strings |
| 1316 | like 5MB. If specified npartitions and divisions will be ignored. Note that |
| 1317 | the size reflects the number of bytes used as computed by |
| 1318 | pandas.DataFrame.memory_usage, which will not necessarily match the size |
| 1319 | when storing to disk. |
| 1320 | |
| 1321 | .. warning:: |
| 1322 | |
| 1323 | This keyword argument triggers computation to determine |
| 1324 | the memory size of each partition, which may be expensive. |
| 1325 | |
| 1326 | force : bool, default False |
| 1327 | Allows the expansion of the existing divisions. |
| 1328 | If False then the new divisions' lower and upper bounds must be |
| 1329 | the same as the old divisions'. |
| 1330 | freq : str, pd.Timedelta |
| 1331 | A period on which to partition timeseries data like ``'7D'`` or |
| 1332 | ``'12h'`` or ``pd.Timedelta(hours=12)``. Assumes a datetime index. |
| 1333 | |
| 1334 | Notes |
| 1335 | ----- |
| 1336 | Exactly one of `divisions`, `npartitions`, `partition_size`, or `freq` |
| 1337 | should be specified. A ``ValueError`` will be raised when that is |
| 1338 | not the case. |
| 1339 | |
| 1340 | Also note that ``len(divisions)`` is equal to ``npartitions + 1``. This is because ``divisions`` |
| 1341 | represents the upper and lower bounds of each partition. The first item is the |
| 1342 | lower bound of the first partition, the second item is the lower bound of the |
| 1343 | second partition and the upper bound of the first partition, and so on. |
| 1344 | The second-to-last item is the lower bound of the last partition, and the last |
| 1345 | (extra) item is the upper bound of the last partition. |