|
8 | 8 |
|
9 | 9 | from pandas._libs import NaT, iNaT, join as libjoin, lib
|
10 | 10 | from pandas._libs.tslibs import timezones
|
| 11 | +from pandas._typing import Label |
11 | 12 | from pandas.compat.numpy import function as nv
|
12 | 13 | from pandas.errors import AbstractMethodError
|
13 | 14 | from pandas.util._decorators import Appender, cache_readonly
|
@@ -649,26 +650,26 @@ def _set_freq(self, freq):
|
649 | 650 |
|
650 | 651 | self._data._freq = freq
|
651 | 652 |
|
652 |
| - def _shallow_copy(self, values=None, **kwargs): |
| 653 | + def _shallow_copy(self, values=None, name: Label = lib.no_default): |
| 654 | + name = self.name if name is lib.no_default else name |
| 655 | + |
653 | 656 | if values is None:
|
654 | 657 | values = self._data
|
655 | 658 |
|
656 | 659 | if isinstance(values, type(self)):
|
657 | 660 | values = values._data
|
658 | 661 | if isinstance(values, np.ndarray):
|
659 | 662 | # TODO: We would rather not get here
|
660 |
| - if kwargs.get("freq") is not None: |
661 |
| - raise ValueError(kwargs) |
662 | 663 | values = type(self._data)(values, dtype=self.dtype)
|
663 | 664 |
|
664 | 665 | attributes = self._get_attributes_dict()
|
665 | 666 |
|
666 |
| - if "freq" not in kwargs and self.freq is not None: |
| 667 | + if self.freq is not None: |
667 | 668 | if isinstance(values, (DatetimeArray, TimedeltaArray)):
|
668 | 669 | if values.freq is None:
|
669 | 670 | del attributes["freq"]
|
670 | 671 |
|
671 |
| - attributes.update(kwargs) |
| 672 | + attributes["name"] = name |
672 | 673 | return type(self)._simple_new(values, **attributes)
|
673 | 674 |
|
674 | 675 | # --------------------------------------------------------------------
|
@@ -738,9 +739,7 @@ def intersection(self, other, sort=False):
|
738 | 739 | # this point, depending on the values.
|
739 | 740 |
|
740 | 741 | result._set_freq(None)
|
741 |
| - result = self._shallow_copy( |
742 |
| - result._data, name=result.name, dtype=result.dtype, freq=None |
743 |
| - ) |
| 742 | + result = self._shallow_copy(result._data, name=result.name) |
744 | 743 | if result.freq is None:
|
745 | 744 | result._set_freq("infer")
|
746 | 745 | return result
|
|
0 commit comments