0

When I try to run the below function:

import polars as pl
from polars_encryption import encrypt, decrypt

def crypt(csv_file: str, delim: str, password: str, output_file: str):
    """
    Save CSV to encrypted Parquet by encrypting all columns
    - csv_file: CSV file path (without .csv extension)
    - delim: CSV delimiter
    - password: Your encryption password
    - output_file: Output Parquet filename
    """
    # Read CSV
    df = pl.read_csv(f"{csv_file}.csv", separator=delim, encoding="UTF-8-SIG")
    
    # Pad/truncate password to 32 bytes (AES-256 key size)
    key = (password.encode() + b'\0'*32)[:32]
    nonce = b'minimal_nonce_'  # 12-byte fixed nonce
    
    # Encrypt all columns
    encrypted_df = df.with_columns([
        encrypt(pl.col(col_name), key=key, nonce=nonce).alias(col_name)
        for col_name in df.columns
    ])
    
    # Save encrypted DataFrame
    encrypted_df.write_parquet(output_file)

With the below perameters:

crypt(csv_file = file, delim = ';', password = 'testpass', output_file = 'new.pa')

I get the following error:

ComputeError: the plugin panicked

The message is suppressed. Set POLARS_VERBOSE=1 to send the panic message to stderr.

Can anyone help me fix this?

5
  • always put full error message because there are other useful information. Commented Jun 17 at 15:11
  • 1
    Have you tried to "Set POLARS_VERBOSE=1 to send the panic message to stderr."? Commented Jun 17 at 16:15
  • Honestly don't use that plugin, either map_elements with a well established library or write your own plugin. Reusing the nonce is a terrible practice, I wouldn't trust a library written by a developer that recommends that Commented Jun 17 at 17:38
  • @etrotta Do you mean for each row/value you'd use a different nonce? Commented Jun 17 at 19:21
  • Notwithstanding what etrotta said, it looks like that hasn't been updated in 5 months so I'm guessing there has been an internal change in polars that doesn't work with whatever version that plugin is based on. Downgrade your polars to one that coincided to the plugin's release. Here is the release history. Commented Jun 17 at 19:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.