Repository: pandas-dev/pandas
Pull request: ENH: Raise error for 'sheet' arg in read_excel
- [ ] closes #17994 

I was also thinking about the possibility of raising a warning instead, and do something like:

```
if sheet in kwds:
    sheet_name = sheet
```

Problem statement:
read_excel does not raise error with wrong keyword arg
For example:
```python
pd.read_excel('file_name.xlsx',sheet='mysheet')
```
does not raise any error. The right parameter name is "sheetname" . If "sheet" is passed it defaults to the first sheet and no error is raised.
 
sheetname and sheet are very similar and easy to confuse. 

One might think that it is reading the sheet passed as argument when in fact it is another one. 

I would like to suggest for errors to be raised if unexpected args are passed.

Hints from issue discussion:
This *may* be little tricky, since IIRC we pass through `**kwargs` to the underlying engine doing the work (though I may be wrong). Can you take a look in `pandas/io/excel.py` to see if there's anything we can do?
@TomAugspurger : You are correct regarding `**kwargs`.  That is indeed quite unfortunate.
Hmm, we could maybe explicitly check for some common mistakes (like `sheet`), verify that none of the engines use them, and raise if we see them? That's fragile to the engines adding them in the future :/
@TomAugspurger : I think we should look into expanding the signature to obviate the need for `**kwargs`.  Ultimately, we would like it to be identical to `read_csv`, but that's another story for another day.
@TomAugspurger: I’m not an experienced programmer, but I could try something. What about something as simple as if parameter passed not in a list of allowed parameters, raise an error?
@lucianoviola : That sounds like a good plan.  Refer to `read_csv` to see which arguments we *can* accept.   Also, use the same error message that you get when you pass in an unexpected argument to a function (i.e. "[function] got an unexpected keyword argument [arg]")
@gfyoung Ok!

Commit message: ENH: Raise error for read_excel possible "sheet" argument in kwargs (#17994)

Patch to review:
diff --git a/pandas/io/excel.py b/pandas/io/excel.py
index fec916dc52d20..087961ce40e09 100644
--- a/pandas/io/excel.py
+++ b/pandas/io/excel.py
@@ -225,6 +225,9 @@ def read_excel(io, sheet_name=0, header=0, skiprows=None, skip_footer=0,
     elif 'sheetname' in kwds:
         raise TypeError("Cannot specify both `sheet_name` and `sheetname`. "
                         "Use just `sheet_name`")
+    if 'sheet' in kwds:
+        raise TypeError("read_excel() got an unexpected keyword argument "
+                        "`sheet`")
 
     if not isinstance(io, ExcelFile):
         io = ExcelFile(io, engine=engine)


Code review comments:
diff_hunk: @@ -225,6 +225,9 @@ def read_excel(io, sheet_name=0, header=0, skiprows=None, skip_footer=0,
     elif 'sheetname' in kwds:
         raise TypeError("Cannot specify both `sheet_name` and `sheetname`. "
                         "Use just `sheet_name`")
+    if 'sheet' in kwds:
+        raise TypeError("read_excel() got an unexpected keyword argument "
+                        "`sheet`")
path: pandas/io/excel.py
text: @user1:
This is not generalizable.  What happens if I were to pass in an argument called "Sheet" ?  Your check wouldn't catch that.  You should develop a more general checker that checks for **any** keywords that don't correspond to ones that we accept.