Skip to content

CLN: remove kwargs from Index._simple_new #29604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def asi8(self):
return None

@classmethod
def _simple_new(cls, values, name=None, dtype=None, **kwargs):
def _simple_new(cls, values, name=None, dtype=None):
"""
We require that we have a dtype compat for the values. If we are passed
a non-dtype compat, then coerce using the constructor.
Expand All @@ -528,8 +528,7 @@ def _simple_new(cls, values, name=None, dtype=None, **kwargs):
# we actually set this value too.
result._index_data = values
result.name = name
for k, v in kwargs.items():
setattr(result, k, v)

return result._reset_identity()

@cache_readonly
Expand Down Expand Up @@ -2673,7 +2672,7 @@ def difference(self, other, sort=None):
except TypeError:
pass

return this._shallow_copy(the_diff, name=result_name, freq=None)
return this._shallow_copy(the_diff, name=result_name)

def symmetric_difference(self, other, result_name=None, sort=None):
"""
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ def _convert_for_op(self, value):
return _to_M8(value)
raise ValueError("Passed item and index have different timezone")

@Appender(Index.difference.__doc__)
def difference(self, other, sort=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a docstring here? (I think you can use one of the decorators to append Index.difference.__doc__)

(and same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

new_idx = super().difference(other, sort=sort)
new_idx.freq = None
return new_idx

# --------------------------------------------------------------------
# Rendering Methods

Expand Down
7 changes: 2 additions & 5 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,18 @@ def from_range(cls, data, name=None, dtype=None):
return cls._simple_new(data, dtype=dtype, name=name)

@classmethod
def _simple_new(cls, values, name=None, dtype=None, **kwargs):
def _simple_new(cls, values, name=None, dtype=None):
result = object.__new__(cls)

# handle passed None, non-integers
if values is None:
# empty
values = range(0, 0, 1)
elif not isinstance(values, range):
return Index(values, dtype=dtype, name=name, **kwargs)
return Index(values, dtype=dtype, name=name)

result._range = values

result.name = name
for k, v in kwargs.items():
setattr(result, k, v)

result._reset_identity()
return result
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ def intersection(self, other, sort=False):
"""
return super().intersection(other, sort=sort)

@Appender(Index.difference.__doc__)
def difference(self, other, sort=None):
new_idx = super().difference(other, sort=sort)
new_idx.freq = None
return new_idx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be shared in one of the datetimelike classes?

Copy link
Contributor Author

@topper-123 topper-123 Nov 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so: PeriodIndex doesn't allow freq=None and DatetimeIndexOpsMixin is shared with that`. Don't know if that's a bug in PeriodIndex or as intended, as I haven't worked much with datetime objects.

My motivation with this is getting kwargs out of a basic method and make child classes just build on that using super + the specific stuff. That is easier to reason about IMO.


def _wrap_joined_index(self, joined, other):
name = get_op_result_name(self, other)
if (
Expand Down