Registry / database / repartipy

repartipy

JSON →
library0.1.8pypypi✓ verified 85d ago

repartipy is a Python library designed to assist with managing PySpark DataFrame partition sizes. It provides a function to repartition a DataFrame based on a target partition size in megabytes, aiming to optimize storage and processing efficiency. As of version 0.1.8, it's a relatively stable and focused utility, with updates likely driven by PySpark compatibility or feature requests rather than a fixed cadence.

pip install repartipy
INSTALL
IMPORT
SIG · REPARTIPY
R
repartipy
databasepythonv0.1.8
Install
1.7s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SizeEstimator
from repartipy import SizeEstimator
from repartipy import repartition_by_size

This quickstart demonstrates how to initialize a SparkSession, create a sample DataFrame, and then use `repartition_by_size` to optimize its partitions. The example aims for 10MB partitions, showing the initial and resulting partition counts. Remember that repartitioning creates a new DataFrame and requires an action (like writing data or collecting) to trigger actual computation.

from pyspark.sql import SparkSession from pyspark.sql.functions import lit from repartipy import repartition_by_size # Create a SparkSession spark = SparkSession.builder \ .appName("repartipy_quickstart") \ .master("local[*]") \ .config("spark.ui.enabled", "false") \ .getOrCreate() try: # Create a dummy DataFrame with approx 100MB of data for demonstration # (adjust range and string size to control actual data size) data = [(i, f"value_{i}") for i in range(100000)] df = spark.createDataFrame(data, ["id", "value"]) # Add a large column to increase row size for a more realistic scenario df = df.withColumn("large_string", lit("x" * 500)) print(f"Initial DataFrame row count: {df.count()}") print(f"Initial partition count: {df.rdd.getNumPartitions()}") # Repartition the DataFrame to aim for 10MB partitions target_size_mb = 10 repartitioned_df = repartition_by_size(df, target_size_mb, spark=spark) print(f"Repartitioned DataFrame row count: {repartitioned_df.count()}") print(f"New partition count (target ~{target_size_mb}MB per partition): {repartitioned_df.rdd.getNumPartitions()}") # Perform an action to trigger the repartitioning and check the result # e.g., repartitioned_df.write.mode("overwrite").parquet("/tmp/repartipy_output") finally: spark.stop()
Debug
Known issues
gotcha`repartition_by_size` returns a new DataFrame. Always assign the result to a new variable or overwrite the original DataFrame, as the operation does not modify the DataFrame in-place.
fix
Always use `new_df = repartition_by_size(old_df, ...)`
affects: All versions
gotchaSpark's repartitioning, especially when aiming for a specific size, involves shuffling data across the cluster, which can be a resource-intensive operation. Use `repartition_by_size` judiciously, especially for very large DataFrames or frequent operations, to avoid performance bottlenecks.
fix
Profile your Spark jobs and understand your data distribution. Only repartition when necessary and consider the impact of the `target_partition_size_mb` on overall job performance.
affects: All versions
gotchaThe `target_partition_size_mb` is an *aim*, not a guarantee. Actual partition sizes can vary based on data skew, compression, and the underlying data storage mechanism. Do not rely on exact partition sizes.
fix
Use the target size as a guideline. Monitor actual partition sizes after repartitioning using Spark UI or metrics to confirm the desired effect. Adjust the target size based on observed results and data characteristics.
affects: All versions
Upgrade
Version history
0.1.8latest on PyPI · released Mar 8, 2024
Audit
Dependencies
pysparkrequiredCore dependency for PySpark DataFrame operations.
Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
repartipy — pip install repartipy · libregistry