Skip to content

Commit b068225

Browse files
committed
Merge pull request #11155 from kawochen/BUG-FIX-11086
BUG/API: GH11086 where freq is not inferred if both freq is None
2 parents 37eb3ec + a705a26 commit b068225

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

doc/source/whatsnew/v0.17.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ Other API Changes
916916
- When constructing ``DataFrame`` with an array of ``complex64`` dtype previously meant the corresponding column
917917
was automatically promoted to the ``complex128`` dtype. Pandas will now preserve the itemsize of the input for complex data (:issue:`10952`)
918918
- some numeric reduction operators would return ``ValueError``, rather than ``TypeError`` on object types that includes strings and numbers (:issue:`11131`)
919-
919+
- ``DatetimeIndex.union`` does not infer ``freq`` if ``self`` and the input have ``None`` as ``freq`` (:issue:`11086`)
920920
- ``NaT``'s methods now either raise ``ValueError``, or return ``np.nan`` or ``NaT`` (:issue:`9513`)
921921

922922
=============================== ===============================================================

pandas/io/pytables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
_default_encoding = 'UTF-8'
5252

5353
def _ensure_decoded(s):
54-
""" if we have bytes, decode them to unicde """
54+
""" if we have bytes, decode them to unicode """
5555
if isinstance(s, np.bytes_):
5656
s = s.decode('UTF-8')
5757
return s

pandas/tseries/index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ def union(self, other):
895895
result = Index.union(this, other)
896896
if isinstance(result, DatetimeIndex):
897897
result.tz = this.tz
898-
if result.freq is None:
898+
if (result.freq is None and
899+
(this.freq is not None or other.freq is not None)):
899900
result.offset = to_offset(result.inferred_freq)
900901
return result
901902

pandas/tseries/tests/test_timeseries.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,15 @@ def test_intersection_bug_1708(self):
25512551
result = index_1 & index_2
25522552
self.assertEqual(len(result), 0)
25532553

2554+
def test_union_freq_both_none(self):
2555+
#GH11086
2556+
expected = bdate_range('20150101', periods=10)
2557+
expected.freq = None
2558+
2559+
result = expected.union(expected)
2560+
tm.assert_index_equal(result, expected)
2561+
self.assertIsNone(result.freq)
2562+
25542563
# GH 10699
25552564
def test_datetime64_with_DateOffset(self):
25562565
for klass, assert_func in zip([Series, DatetimeIndex],

0 commit comments

Comments
 (0)