Mapping function not working if the first example is returned as None
MEMBER
Hi, map() always expect an output.

If you wish to filter examples, you should use filter(), in your case it could be something like this:

```python
ds = ds.map(my_processing_function).filter(ignore_long_prompts)
```
2025-07-09T10:30:39Z
https://github.com/huggingface/datasets/issues/7671#issuecomment-3052108458
https://api.github.com/repos/huggingface/datasets/issues/7671
IC_kwDODunzps6163qq
https://api.github.com/repos/huggingface/datasets/issues/comments/3052108458/reactions
2025-07-09T10:30:39Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3052108458
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
NONE
Realized this! Thanks a lot, I will close this issue then.
2025-07-09T12:30:32Z
https://github.com/huggingface/datasets/issues/7671#issuecomment-3052492460
https://api.github.com/repos/huggingface/datasets/issues/7671
IC_kwDODunzps618Vas
https://api.github.com/repos/huggingface/datasets/issues/comments/3052492460/reactions
2025-07-09T12:30:32Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3052492460
https://avatars.githubusercontent.com/u/46325823?v=4
https://api.github.com/users/dnaihao/events{/privacy}
https://api.github.com/users/dnaihao/followers
https://api.github.com/users/dnaihao/following{/other_user}
https://api.github.com/users/dnaihao/gists{/gist_id}
https://github.com/dnaihao
dnaihao
MDQ6VXNlcjQ2MzI1ODIz
https://api.github.com/users/dnaihao/orgs
https://api.github.com/users/dnaihao/received_events
https://api.github.com/users/dnaihao/repos
https://api.github.com/users/dnaihao/starred{/owner}{/repo}
https://api.github.com/users/dnaihao/subscriptions
User
https://api.github.com/users/dnaihao
public
### Describe the bug

https://github.com/huggingface/datasets/blob/8a19de052e3d79f79cea26821454bbcf0e9dcd68/src/datasets/arrow_dataset.py#L3652C29-L3652C37

Here we can see the writer is initialized on `i==0`. However, there can be cases where in the user mapping function, the first example is filtered out (length constraints, etc).

In this case, the writer would be a `None` type and the code will report `NoneType has no write function`.

A simple fix is available, simply change line 3652 from `if i == 0:` to `if writer is None:`

### Steps to reproduce the bug

Prepare a dataset

have this function

```
import datasets


def make_map_fn(split, max_prompt_tokens=3):
    def process_fn(example, idx):

        question = example['question']
        reasoning_steps = example['reasoning_steps']
        label = example['label']

        answer_format = ""
        for i in range(len(reasoning_steps)):
            system_message = "Dummy"

        all_steps_formatted = []

        content = f"""Dummy"""

        prompt = [
            {"role": "system", "content": system_message},
            {"role": "user", "content": content},
        ]
        tokenized = tokenizer.apply_chat_template(prompt, return_tensors="pt", truncation=False)
        if tokenized.shape[1] > max_prompt_tokens:
            return None  # skip overly long examples

        data = {
            "dummy": "dummy"
        }

        return data

    return process_fn

...
# load your dataset
...
train = train.map(function=make_map_fn('train'), with_indices=True)
```

### Expected behavior

The dataset mapping shall behave even when the first example is filtered out.

### Environment info

I am using `datasets==3.6.0` but I have observed this issue in the github repo too: https://github.com/huggingface/datasets/blob/8a19de052e3d79f79cea26821454bbcf0e9dcd68/src/datasets/arrow_dataset.py#L3652C29-L3652C37