FIX # 45957 issue read_csv with empty list
State: closed

- [ ] closes #45957 (Replace xxxx with the Github issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


Labels:
name: IO CSV
description: read_csv, to_csv

Comments:
Hello @profMsaif! Thanks for opening this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

* In the file [`pandas/io/parsers/readers.py`](https://github.com/pandas-dev/pandas/blob/e39c29a07a2b31d2722a00c17c90d123ddcc1865/pandas/io/parsers/readers.py):

> [Line 1206:9](https://github.com/pandas-dev/pandas/blob/e39c29a07a2b31d2722a00c17c90d123ddcc1865/pandas/io/parsers/readers.py#L1206): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1206:69](https://github.com/pandas-dev/pandas/blob/e39c29a07a2b31d2722a00c17c90d123ddcc1865/pandas/io/parsers/readers.py#L1206): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 1207:9](https://github.com/pandas-dev/pandas/blob/e39c29a07a2b31d2722a00c17c90d123ddcc1865/pandas/io/parsers/readers.py#L1207): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '


I think `TextParser` can call `TextFileReader` with a list but `TextParser` always uses the python engine. I would recommend adding something like this after the if block:

```py
elif engine != "python":
    raise TypeError("Lists are only supported with engine='python'.")
```
Probably need to phrase it differently: I don't think we want to encourage people calling `read_csv` with lists.

> I think `TextParser` can call `TextFileReader` with a list but `TextParser` always uses the python engine. I would recommend adding something like this after the if block:
> 
> ```python
> elif engine != "python":
>     raise TypeError("Lists are only supported with engine='python'.")
> ```
> 
> Probably need to phrase it differently: I don't think we want to encourage people calling `read_csv` with lists.

This message will be not informative for the pandas user, 
As read_csv expect file of file path or a iobuffer 
List or any other object should never be a valid value for this variable.
 The behaviour of pandas older version like (1.2.* or 1.3.*) was with ValueError , no matter what you pass dict list tuple it will always raise ValueError and I think this behaviour shouldn’t changed 
Then how about raising exactly the same error as in previous versions?

```py
elif engine != "python":
    # read_excel uses the python engine with a list
    raise ValueError(f"Invalid file path or buffer object type: {type(f)}")
```

Please don't forget to also add a test case.


edit:

Or could have something like this
```py
if isinstance(filepath_or_buffer, list):
     ValueError(f"Invalid file path or buffer object type: {type(f)}")
``` 
around here https://github.com/pandas-dev/pandas/blob/971752a32927e78ed6f0c9ff5afca7cf82662f7a/pandas/io/parsers/readers.py#L542

closing as fixed by #46325. Thanks @profMsaif for the PR.