pandas: Index constructor doesn't validate kwargs

In [4]: pd.Index([1, 2], abc=1)                                                                                                                                                                                                                                                                                                                                           
Out[4]: Int64Index([1, 2], dtype='int64')

This should raise, since abc isn’t a valid keyword.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (15 by maintainers)

Most upvoted comments

Alrighty, sorry for bringing that other discussion in here.

For now @bartkim0426 can you implement https://github.com/pandas-dev/pandas/issues/26974#issuecomment-522561054?

I was confused about always pass **kwargs through to the subclasses constructor. For subclasses - if there are invalid args, TypeError occurred so I think we don’t have to validate the subclasses.

The idea would be for pd.Index([], dtype='category', not_a_kwargs="foo") to raise. I think you don’t pass **kwargs through to all the index subclasses, there might be a case where we don’t raise on that. Make sense?