Skip to content

Commit e6c7d7e

Browse files
HannahFerchvictor
authored and
victor
committed
BUG: DataFrame.apply not adding a frequency if freq=None (pandas-dev#22150) (pandas-dev#22561)
1 parent 8f144bb commit e6c7d7e

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ Datetimelike
636636
- Bug in :meth:`DataFrame.eq` comparison against ``NaT`` incorrectly returning ``True`` or ``NaN`` (:issue:`15697`, :issue:`22163`)
637637
- Bug in :class:`DatetimeIndex` subtraction that incorrectly failed to raise ``OverflowError`` (:issue:`22492`, :issue:`22508`)
638638
- Bug in :class:`DatetimeIndex` incorrectly allowing indexing with ``Timedelta`` object (:issue:`20464`)
639-
-
639+
- Bug in :class:`DatetimeIndex` where frequency was being set if original frequency was ``None`` (:issue:`22150`)
640640

641641
Timedelta
642642
^^^^^^^^^

pandas/core/indexes/datetimes.py

-2
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,6 @@ def union_many(self, others):
860860
if isinstance(this, DatetimeIndex):
861861
this._tz = timezones.tz_standardize(tz)
862862

863-
if this.freq is None:
864-
this.freq = to_offset(this.inferred_freq)
865863
return this
866864

867865
def join(self, other, how='left', level=None, return_indexers=False,

pandas/tests/frame/test_apply.py

+23
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import warnings
1313
import numpy as np
14+
from hypothesis import given
15+
from hypothesis.strategies import composite, dates, integers, sampled_from
1416

1517
from pandas import (notna, DataFrame, Series, MultiIndex, date_range,
1618
Timestamp, compat)
@@ -1155,3 +1157,24 @@ def test_agg_cython_table_raises(self, df, func, expected, axis):
11551157
# GH21224
11561158
with pytest.raises(expected):
11571159
df.agg(func, axis=axis)
1160+
1161+
@composite
1162+
def indices(draw, max_length=5):
1163+
date = draw(
1164+
dates(
1165+
min_value=Timestamp.min.ceil("D").to_pydatetime().date(),
1166+
max_value=Timestamp.max.floor("D").to_pydatetime().date(),
1167+
).map(Timestamp)
1168+
)
1169+
periods = draw(integers(0, max_length))
1170+
freq = draw(sampled_from(list("BDHTS")))
1171+
dr = date_range(date, periods=periods, freq=freq)
1172+
return pd.DatetimeIndex(list(dr))
1173+
1174+
@given(index=indices(5), num_columns=integers(0, 5))
1175+
def test_frequency_is_original(self, index, num_columns):
1176+
# GH22150
1177+
original = index.copy()
1178+
df = DataFrame(True, index=index, columns=range(num_columns))
1179+
df.apply(lambda x: x)
1180+
assert index.freq == original.freq

0 commit comments

Comments
 (0)