Repository: dask/dask
File: dask/dataframe/io/parquet/core.py (Python)

Code before:
                    "index: {} | column: {}".format(index, columns)
                )

        # Leaving index as a column in `meta`, because the index
        # will be reset below (in case the index was detected after
        # meta was created)
        if index_in_columns:
            meta = meta[columns + index]
        else:
            meta = meta[columns]

    else:
        meta = meta[list(columns)]

    return meta, index, columns


def aggregate_row_groups(parts, stats, chunksize):
    if not (stats[0]["file_path_0"] and stats[0]["total_byte_size"]):
        return parts, stats

    chunksize = parse_bytes(chunksize)

    def _add_piece(part, part_list, stat, stat_list):
        part_list.append(part)
        stat_list.append(stat)

    def _update_piece(part, next_part, stat, next_stat):
        # Update part list
        next_part.append(part)

        # Update Statistics
        next_stat["total_byte_size"] += stat["total_byte_size"]
        next_stat["num-rows"] += stat["num-rows"]
        for col, col_add in zip(next_stat["columns"], stat["columns"]):
            if col["name"] != col_add["name"]:
                raise ValueError("Columns are different!!")
            if "null_count" in col:
                col["null_count"] += col_add["null_count"]
            if "min" in col:
                col["min"] = min(col["min"], col_add["min"])
            if "max" in col:
                col["max"] = max(col["max"], col_add["max"])

    parts_agg = []
    stats_agg = []
    next_part, next_stat = [parts[0].copy()], stats[0].copy()
    for i in range(1, len(parts)):
        stat, part = stats[i], parts[i]
        if (stat["file_path_0"] == next_stat["file_path_0"]) and (
            (next_stat["total_byte_size"] + stat["total_byte_size"]) <= chunksize

Review comment (security):
This only gets used twice.  If it's ok I'd prefer to just append to these lists in place.  I find that code with indirection like this makes it a bit harder for people other than the author to review it in the future.

Code after:
        else:
            meta = meta[columns]

    else:
        meta = meta[list(columns)]

    return meta, index, columns


def aggregate_row_groups(parts, stats, chunksize):
    if not stats[0]["file_path_0"]:
        return parts, stats

    parts_agg = []
    stats_agg = []
    chunksize = parse_bytes(chunksize)
    next_part, next_stat = [parts[0].copy()], stats[0].copy()
    for i in range(1, len(parts)):
        stat, part = stats[i], parts[i]
        if (stat["file_path_0"] == next_stat["file_path_0"]) and (
            (next_stat["total_byte_size"] + stat["total_byte_size"]) <= chunksize
        ):
            # Update part list
            next_part.append(part)

            # Update Statistics
            next_stat["total_byte_size"] += stat["total_byte_size"]
            next_stat["num-rows"] += stat["num-rows"]
            for col, col_add in zip(next_stat["columns"], stat["columns"]):
                if col["name"] != col_add["name"]:
                    raise ValueError("Columns are different!!")
                if "null_count" in col:
                    col["null_count"] += col_add["null_count"]
                if "min" in col:
                    col["min"] = min(col["min"], col_add["min"])
                if "max" in col:
                    col["max"] = max(col["max"], col_add["max"])
        else:
            parts_agg.append(next_part)
            stats_agg.append(next_stat)
            next_part, next_stat = [part.copy()], stat.copy()

    parts_agg.append(next_part)
    stats_agg.append(next_stat)

    return parts_agg, stats_agg


DataFrame.to_parquet.__doc__ = to_parquet.__doc__