-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Retain name in PeriodIndex resample #12771
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
Closed
max-sixty
wants to merge
1
commit into
pandas-dev:master
from
max-sixty:retain-period-index-name-on-resample
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
# pylint: disable-msg=E1101,W0612 | ||
import calendar | ||
from datetime import datetime, time, timedelta | ||
import sys | ||
import operator | ||
import sys | ||
import warnings | ||
from datetime import datetime, time, timedelta | ||
from numpy.random import rand | ||
from numpy.testing.decorators import slow | ||
|
||
import nose | ||
import numpy as np | ||
import pandas.tseries.frequencies as frequencies | ||
import pandas.index as _index | ||
import pandas.lib as lib | ||
import pandas.tslib as tslib | ||
import pandas.index as _index | ||
import pandas as pd | ||
from pandas import (Index, Series, DataFrame, isnull, date_range, Timestamp, | ||
Period, DatetimeIndex, Int64Index, to_datetime, | ||
bdate_range, Float64Index, NaT, timedelta_range, Timedelta) | ||
|
||
from pandas.compat.numpy_compat import np_datetime64_compat | ||
import pandas as pd | ||
import pandas.compat as compat | ||
import pandas.core.common as com | ||
import pandas.core.datetools as datetools | ||
import pandas.tseries.frequencies as frequencies | ||
import pandas.tseries.offsets as offsets | ||
import pandas.tseries.tools as tools | ||
|
||
|
||
from pandas.util.testing import assert_series_equal, assert_almost_equal,\ | ||
_skip_if_has_locale | ||
import pandas.util.testing as tm | ||
|
||
from pandas.tslib import iNaT | ||
|
||
from pandas import ( | ||
Index, Series, DataFrame, isnull, date_range, Timestamp, Period, | ||
DatetimeIndex, Int64Index, to_datetime, bdate_range, Float64Index, | ||
NaT, timedelta_range, Timedelta, _np_version_under1p8, concat, | ||
PeriodIndex) | ||
from pandas.compat import range, long, StringIO, lrange, lmap, zip, product | ||
from numpy.random import rand | ||
from pandas.util.testing import assert_frame_equal | ||
from pandas.compat.numpy_compat import np_datetime64_compat | ||
from pandas.core.common import PerformanceWarning | ||
import pandas.compat as compat | ||
import pandas.core.common as com | ||
from pandas import concat | ||
from pandas import _np_version_under1p8 | ||
|
||
from numpy.testing.decorators import slow | ||
from pandas.tslib import iNaT | ||
from pandas.util.testing import ( | ||
assert_frame_equal, assert_series_equal, assert_almost_equal, | ||
_skip_if_has_locale) | ||
|
||
randn = np.random.randn | ||
|
||
|
@@ -2249,15 +2245,27 @@ def test_concat_datetime_datetime64_frame(self): | |
def test_period_resample(self): | ||
# GH3609 | ||
s = Series(range(100), index=date_range( | ||
'20130101', freq='s', periods=100), dtype='float') | ||
'20130101', freq='s', periods=100, name='idx'), dtype='float') | ||
s[10:30] = np.nan | ||
expected = Series([34.5, 79.5], index=[Period( | ||
'2013-01-01 00:00', 'T'), Period('2013-01-01 00:01', 'T')]) | ||
index = PeriodIndex([ | ||
Period('2013-01-01 00:00', 'T'), | ||
Period('2013-01-01 00:01', 'T')], name='idx') | ||
expected = Series([34.5, 79.5], index=index) | ||
result = s.to_period().resample('T', kind='period').mean() | ||
assert_series_equal(result, expected) | ||
result2 = s.resample('T', kind='period').mean() | ||
assert_series_equal(result2, expected) | ||
|
||
def test_empty_period_index_resample(self): | ||
# GH12771 | ||
index = PeriodIndex(start='2000', periods=0, freq='D', name='idx') | ||
s = Series(index=index) | ||
result = s.resample('M').sum() | ||
# after GH12774 is resolved, this should be a PeriodIndex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great. put a pointer to this PR in that issue (and maybe a checkbox), so we don't forget. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
expected_index = DatetimeIndex([], name='idx') | ||
expected = Series(index=expected_index) | ||
assert_series_equal(result, expected) | ||
|
||
def test_period_resample_with_local_timezone_pytz(self): | ||
# GH5430 | ||
tm._skip_if_no_pytz() | ||
|
@@ -2297,7 +2305,7 @@ def test_period_resample_with_local_timezone_dateutil(self): | |
end = datetime(year=2013, month=11, day=2, hour=0, minute=0, | ||
tzinfo=dateutil.tz.tzutc()) | ||
|
||
index = pd.date_range(start, end, freq='H') | ||
index = pd.date_range(start, end, freq='H', name='idx') | ||
|
||
series = pd.Series(1, index=index) | ||
series = series.tz_convert(local_timezone) | ||
|
@@ -2306,7 +2314,8 @@ def test_period_resample_with_local_timezone_dateutil(self): | |
# Create the expected series | ||
# Index is moved back a day with the timezone conversion from UTC to | ||
# Pacific | ||
expected_index = (pd.period_range(start=start, end=end, freq='D') - 1) | ||
expected_index = (pd.period_range(start=start, end=end, freq='D', | ||
name='idx') - 1) | ||
expected = pd.Series(1, index=expected_index) | ||
assert_series_equal(result, expected) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests this, which was untested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number (or in this case the PR number as you are fixing something unrealted to the original issue)