why I got a list instead of datasets.arrow_dataset.Column after the map?
#7838
Replies: 2 comments
-
|
This is expected behavior — After calling How to work with the result correctly# After map, column access returns a list
result = dataset.map(lambda x: {"new_col": x["text"].upper()})
print(type(result["new_col"])) # <class list>
# To get a proper column object, use .data
import pyarrow as pa
col = result.data["new_col"] # pyarrow.ChunkedArray
# Or convert to pandas
df = result.to_pandas()
print(df["new_col"]) # pandas SeriesIf you need the Arrow column object# Access via the underlying Arrow table
arrow_col = result._data["new_col"] # ChunkedArrayWhy this happensHuggingFace datasets stores data in Arrow format internally. The For most use cases, the list access is what you want. Use |
Beta Was this translation helpful? Give feedback.
-
|
What you're seeing is expected behavior.
reasoning_dataset.map(generate_conversation, batched=True)["conversations"]you're no longer working with the For a Hugging Face mapped_dataset = reasoning_dataset.map(
generate_conversation,
batched=True
)
type(mapped_dataset)
# datasets.arrow_dataset.Dataset
type(mapped_dataset["conversations"])
# listSo the difference is:
If you were expecting a If you want to keep working with the dataset structure, assign the result of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions