On huggingface, some datasets use parquet format. What is it? How can I make my data…
- User
On huggingface, some datasets use parquet format. What is it? How can I make my data (currently json) in the parquet format?
Assistant
- User
This is how I creat the json file currently: examples = [] for... example = {"conversation_id": data["conversation_hash"], "conversation": conv, "source": "https://huggingface.co/datasets/allenai/WildChat-4.8M", "model_name": data["model"], "user_id": data["hashed_ip"], "user_metadata": user_metadata, "timestamp": data["timestamp"], "conversation_metadata": conversation_metadata} examples.append(example) wildchat_formatted_dataset = pd.DataFrame(examples) wildchat_formatted_dataset.to_json('wildchat_formatted.json', orient='records', force_ascii=False, default_handler=str) Should I create the Parquet from the list? or is it better to go through the json?
Assistant
- User
Assistant
This error is a Schema Mismatch.The Hugging Face Hub (specifically the dataset viewer) is trying to interpret your conversation column as a standard "Chat" format, which strictly expects a list of objects containing only role and content.However, your conv variable contains "raw" objects with many extra fields (like country, hashed_ip, header, usage, etc.). Parquet is trying to force those complex objects into the simple {'role': string, 'content': string} shape, and it fails because the shapes don't match.The Fix: Clean the Conversation ListYou need to filter the conv list inside your loop so that you only save the role and content for each message.Here is the corrected code snippet:Pythonimport pandas as pd
- User
ok, I fixed it, thanks. Now I'm getting this error when loading the dataset Generating train split: 350718 examples [00:46, 3928.76 examples/s]Failed to load JSON from file '/cs/usr/shachar.don/.cache/huggingface/hub/datasets--shachardon--ShareLM/snapshots/XXX/wildchat_formatted_37000.parquet' with error <class 'pyarrow.lib.ArrowInvalid'>: JSON parse error: Invalid value. in row 0
Assistant
This error is happening because your code is trying to read the Parquet file as if it were a JSON file.The error message JSON parse error on a .parquet file confirms that the loading function expects text (JSON) but found binary data (Parquet), causing it to crash immediately.Here is how to fix it, depending on how you are loading the data:Scenario 1: You are loading from a local fileIf you are running the script locally, you likely have json specified in your load command.Incorrect:Python# This forces it to use the JSON loader on a Parquet file -> CRASH dataset = load_dataset("json", data_files="wildchat_formatted_37000.parquet") Correct: Change "json" to "parquet".Pythondataset = load_dataset("parquet", data_files="wildchat_formatted_37000.parquet") Scenario 2: You are loading from the Hugging Face HubThe file path in your error (.../snapshots/...) suggests you uploaded the data to the Hub and are pulling it down.If you uploaded the .parquet file but are still getting this error, it is usually because of the README.md (Dataset Card) in your repository.Go to your dataset page on Hugging Face ( at the README.md file.Check the YAML metadata block at the very top (between the --- lines).It likely looks like this (Old Metadata):YAMLconfigs:
- User
I have there other files that are still in json format
Assistant
That explains the error perfectly!Here is exactly what is happening: When Hugging Face sees a folder with both .json and .parquet files, it gets confused. It often defaults to "JSON mode" because of the existing files, finds your new Parquet file, tries to read it as text, and crashes.You have two ways to fix this:Option 1: Force it to read only the Parquet file (Quick Fix)If you just want to load your new data and ignore the old JSON files for now, you must explicitly tell load_dataset to target the Parquet file.Use the data_files argument:Pythonfrom datasets import load_dataset
This tells HF: "Ignore the JSON files, only look for the parquet ones"
dataset = load_dataset( "shachardon/ShareLM", data_files="*.parquet", # OR specific name: "wildchat_formatted_37000.parquet" split="train" ) Option 2: Clean up the Repository (Recommended)It is generally bad practice to keep mixed file formats in the same dataset directory, as it breaks the automatic "Dataset Viewer" on the Hugging Face website.I highly recommend you convert the remaining JSON files to Parquet and delete the JSON versions.Convert the old JSONs: Use the same pandas script you just used for the wildchat data on your other files.Delete the JSONs from the repo:Bash# If you are using git for the repo rm *.json git add . git commit -m "Migrate all data to parquet" git push Once the repository only contains .parquet files, load_dataset("shachardon/ShareLM") will work automatically without any extra arguments.Would you like me to generate a quick script to loop through a folder and convert all existing JSON files to Parquet automatically?
- User
yes please
Assistant
- User
json_files = glob.glob("*.json") I want to provide another input folder to look for json files in there
Assistant
You can easily modify the script to target a specific folder using os.path.join. This ensures the code works correctly whether you are on Windows () or Linux/Mac (/).Here is the updated script. I added an input_folder variable at the top where you can specify your path.Pythonimport pandas as pd import glob import os
--- CONFIGURATION ---
Put your folder path here.
- User
FAILED to convert downloaded_data_hf/gpt_role_play_classmate_formatted.json: Cannot write struct type 'user_metadata' with no child field to Parquet. Consider adding a dummy child field.
Assistant
- User
the problamatic user_metadata fields are empty dicts (i.e. {}) instead of {"age": "", "gender": "", "location": ""}
Assistant
- User
and the same for "conversation_metadata": {"custom_instruction": "", "language": "", "rate": "", "redacted": "", "status": "", "title": "", "toxic": ""}
Assistant
- User
good. Now, in the past I had problems with Hebrew content due to encoding issues. Should I do something special here to prevent it?
Assistant
Great news: Parquet is actually much safer for Hebrew than CSV or JSON.Unlike CSVs (which often struggle with Excel encoding like Windows-1255 vs UTF-8) or JSON (which sometimes escapes characters as \u05d4...), Parquet enforces UTF-8 encoding strictly.However, the "danger zone" is the moment you read the JSON file into Pandas. If Pandas misinterprets the input file encoding, the damage is done before it even gets to Parquet.To be 100% safe, you only need to add one explicit argument to your reading line.The ModificationIn the script I gave you, change this line:Python# OLD df = pd.read_json(filepath)
- User
yes
Assistant