Skip to content

Commit 16965c5

Browse files
committed
Previously failed tests paassing
let's see what's broken now.
1 parent 5703681 commit 16965c5

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

pandas/core/indexes/datetimelike.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import pandas.tseries.frequencies as frequencies
4343
from pandas.util._decorators import Appender, cache_readonly
4444
import pandas.core.dtypes.concat as _concat
45-
import pandas.core.indexes.api as _api
4645

4746
import pandas.core.indexes.base as ibase
4847
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
@@ -804,8 +803,7 @@ def intersection(self, other):
804803
self._assert_can_do_setop(other)
805804

806805
if self.equals(other):
807-
name = _api._get_consensus_names((self, other))[0]
808-
return self._shallow_copy(self, name=name)
806+
return self._get_reconciled_name_object(other)
809807

810808
lengths = len(self), len(other)
811809
if lengths[0] == 0:
@@ -814,21 +812,25 @@ def intersection(self, other):
814812
return other
815813

816814
if (not index_offsets_equal(self, other) or
815+
not other.freq.isAnchored() or # Fixes period intersections when freq is set
817816
(not self._is_strictly_monotonic or
818817
not other._is_strictly_monotonic)):
819818
result = Index.intersection(self, other)
819+
if result.empty:
820+
result = result.astype(self.dtype)
820821
result = self._shallow_copy(result._values, name=result.name,
821822
freq=None
822823
)
823824
if result.freq is None:
824825
result.offset = frequencies.to_offset(result.inferred_freq)
826+
# attempt a naive guess at the freq.
827+
result.freq = self.freq or other.freq
825828
return result
826829

827830
# Conditions met!
828831
intersected_slice = self._fast_intersection(other)
829-
name = _api._get_consensus_names((self, other))[0]
830-
intersected = self._shallow_copy(intersected_slice, name=name)
831-
return intersected
832+
name = ops.get_op_result_name(self, other)
833+
return self._shallow_copy(intersected_slice, name=name)
832834

833835
def _ensure_datetimelike_to_i8(other, to_utc=False):
834836
"""

pandas/core/indexes/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def _maybe_cast_slice_bound(self, label, side, kind):
755755
Value of `side` parameter should be validated in caller.
756756
757757
"""
758-
assert kind in ['ix', 'loc', 'getitem']
758+
assert kind in ['ix', 'loc', 'getitem', None]
759759

760760
if isinstance(label, datetime):
761761
return Period(label, freq=self.freq)

pandas/tests/indexes/datetimes/test_setops.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_intersection2(self):
133133

134134
third = Index(['a', 'b', 'c'])
135135
result = first.intersection(third)
136-
expected = pd.Index([], dtype=object)
136+
expected = DatetimeIndex([])
137137
tm.assert_index_equal(result, expected)
138138

139139
@pytest.mark.parametrize("tz", [None, 'Asia/Tokyo', 'US/Eastern',
@@ -151,7 +151,7 @@ def test_intersection(self, tz):
151151
expected3 = date_range('6/1/2000', '6/20/2000', freq='D', name=None)
152152

153153
rng4 = date_range('7/1/2000', '7/31/2000', freq='D', name='idx')
154-
expected4 = DatetimeIndex([], name='idx')
154+
expected4 = DatetimeIndex([], name='idx', freq='D')
155155

156156
for (rng, expected) in [(rng2, expected2), (rng3, expected3),
157157
(rng4, expected4)]:
@@ -181,14 +181,14 @@ def test_intersection(self, tz):
181181
# GH 7880
182182
rng4 = date_range('7/1/2000', '7/31/2000', freq='D', tz=tz,
183183
name='idx')
184-
expected4 = DatetimeIndex([], tz=tz, name='idx')
184+
expected4 = DatetimeIndex([], tz=tz, name='idx', freq='D')
185185

186186
for (rng, expected) in [(rng2, expected2), (rng3, expected3),
187187
(rng4, expected4)]:
188188
result = base.intersection(rng)
189189
tm.assert_index_equal(result, expected)
190190
assert result.name == expected.name
191-
assert result.freq is None
191+
assert result.freq == expected.freq
192192
assert result.tz == expected.tz
193193

194194
def test_intersection_empty(self):

0 commit comments

Comments
 (0)