Skip to content

BUG: Fixed bug in selecting month/quarter/year from a series would not select correctly (GH3546) #3548

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

Merged
merged 1 commit into from
May 8, 2013
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
3 changes: 3 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pandas 0.11.1
- Fix to_csv to handle non-unique columns (GH3495_)
- Fixed bug in groupby with empty series referencing a variable before assignment. (GH3510_)
- Fixed bug in mixed-frame assignment with aligned series (GH3492_)
- Fixed bug in selecting month/quarter/year from a series would not select the time element
on the last day (GH3546_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand All @@ -100,6 +102,7 @@ pandas 0.11.1
.. _GH3457: https://github.com/pydata/pandas/issues/3457
.. _GH3477: https://github.com/pydata/pandas/issues/3457
.. _GH3461: https://github.com/pydata/pandas/issues/3461
.. _GH3546: https://github.com/pydata/pandas/issues/3546
.. _GH3468: https://github.com/pydata/pandas/issues/3468
.. _GH3448: https://github.com/pydata/pandas/issues/3448
.. _GH3449: https://github.com/pydata/pandas/issues/3449
Expand Down
6 changes: 3 additions & 3 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,16 +1075,16 @@ def _partial_date_slice(self, reso, parsed, use_lhs=True, use_rhs=True):

if reso == 'year':
t1 = Timestamp(datetime(parsed.year, 1, 1), tz=self.tz)
t2 = Timestamp(datetime(parsed.year, 12, 31), tz=self.tz)
t2 = Timestamp(datetime(parsed.year, 12, 31, 23, 59, 59, 999999), tz=self.tz)
elif reso == 'month':
d = tslib.monthrange(parsed.year, parsed.month)[1]
t1 = Timestamp(datetime(parsed.year, parsed.month, 1), tz=self.tz)
t2 = Timestamp(datetime(parsed.year, parsed.month, d), tz=self.tz)
t2 = Timestamp(datetime(parsed.year, parsed.month, d, 23, 59, 59, 999999), tz=self.tz)
elif reso == 'quarter':
qe = (((parsed.month - 1) + 2) % 12) + 1 # two months ahead
d = tslib.monthrange(parsed.year, qe)[1] # at end of month
t1 = Timestamp(datetime(parsed.year, parsed.month, 1), tz=self.tz)
t2 = Timestamp(datetime(parsed.year, qe, d), tz=self.tz)
t2 = Timestamp(datetime(parsed.year, qe, d, 23, 59, 59, 999999), tz=self.tz)
elif (reso == 'day' and (self._resolution < Resolution.RESO_DAY or not is_monotonic)):
st = datetime(parsed.year, parsed.month, parsed.day)
t1 = Timestamp(st, tz=self.tz)
Expand Down
16 changes: 16 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ def test_indexing(self):
result = df['2001']['A']
assert_series_equal(expected,result)

# GH3546 (not including times on the last day)
idx = date_range(start='2013-05-31 00:00', end='2013-05-31 23:00', freq='H')
ts = Series(range(len(idx)), index=idx)
expected = ts['2013-05']
assert_series_equal(expected,ts)

idx = date_range(start='2013-05-31 00:00', end='2013-05-31 23:59', freq='S')
ts = Series(range(len(idx)), index=idx)
expected = ts['2013-05']
assert_series_equal(expected,ts)

idx = [ Timestamp('2013-05-31 00:00'), Timestamp(datetime(2013,5,31,23,59,59,999999))]
ts = Series(range(len(idx)), index=idx)
expected = ts['2013']
assert_series_equal(expected,ts)

def assert_range_equal(left, right):
assert(left.equals(right))
assert(left.freq == right.freq)
Expand Down