Skip to content
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

BUG: DataFrame.apply not adding a frequency if freq=None (#22150) #22561

Merged
merged 6 commits into from
Sep 18, 2018
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ Datetimelike
- Bug in :meth:`DataFrame.eq` comparison against ``NaT`` incorrectly returning ``True`` or ``NaN`` (:issue:`15697`, :issue:`22163`)
- Bug in :class:`DatetimeIndex` subtraction that incorrectly failed to raise ``OverflowError`` (:issue:`22492`, :issue:`22508`)
- Bug in :class:`DatetimeIndex` incorrectly allowing indexing with ``Timedelta`` object (:issue:`20464`)
-
- Bug in :class:`DatetimeIndex` where frequency was being set if original frequency was ``None`` (:issue:`22150`)

Timedelta
^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,6 @@ def union_many(self, others):
if isinstance(this, DatetimeIndex):
this._tz = timezones.tz_standardize(tz)

if this.freq is None:
this.freq = to_offset(this.inferred_freq)
return this

def join(self, other, how='left', level=None, return_indexers=False,
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import warnings
import numpy as np
from hypothesis import given
from hypothesis.strategies import composite, dates, integers, sampled_from

from pandas import (notna, DataFrame, Series, MultiIndex, date_range,
Timestamp, compat)
Expand Down Expand Up @@ -1155,3 +1157,24 @@ def test_agg_cython_table_raises(self, df, func, expected, axis):
# GH21224
with pytest.raises(expected):
df.agg(func, axis=axis)

@composite
def indices(draw, max_length=5):
date = draw(
dates(
min_value=Timestamp.min.ceil("D").to_pydatetime().date(),
max_value=Timestamp.max.floor("D").to_pydatetime().date(),
).map(Timestamp)
)
periods = draw(integers(0, max_length))
freq = draw(sampled_from(list("BDHTS")))
dr = date_range(date, periods=periods, freq=freq)
return pd.DatetimeIndex(list(dr))

@given(index=indices(5), num_columns=integers(0, 5))
def test_frequency_is_original(self, index, num_columns):
# GH22150
original = index.copy()
df = DataFrame(True, index=index, columns=range(num_columns))
df.apply(lambda x: x)
assert index.freq == original.freq