Skip to content

Commit 17e1f21

Browse files
committed
Merge pull request #3548 from jreback/GH3546
BUG: Fixed bug in selecting month/quarter/year from a series would not select correctly (GH3546)
2 parents d925966 + a23db0c commit 17e1f21

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pandas 0.11.1
7979
- Fix to_csv to handle non-unique columns (GH3495_)
8080
- Fixed bug in groupby with empty series referencing a variable before assignment. (GH3510_)
8181
- Fixed bug in mixed-frame assignment with aligned series (GH3492_)
82+
- Fixed bug in selecting month/quarter/year from a series would not select the time element
83+
on the last day (GH3546_)
8284

8385
.. _GH3164: https://github.com/pydata/pandas/issues/3164
8486
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -100,6 +102,7 @@ pandas 0.11.1
100102
.. _GH3457: https://github.com/pydata/pandas/issues/3457
101103
.. _GH3477: https://github.com/pydata/pandas/issues/3457
102104
.. _GH3461: https://github.com/pydata/pandas/issues/3461
105+
.. _GH3546: https://github.com/pydata/pandas/issues/3546
103106
.. _GH3468: https://github.com/pydata/pandas/issues/3468
104107
.. _GH3448: https://github.com/pydata/pandas/issues/3448
105108
.. _GH3449: https://github.com/pydata/pandas/issues/3449

pandas/tseries/index.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1075,16 +1075,16 @@ def _partial_date_slice(self, reso, parsed, use_lhs=True, use_rhs=True):
10751075

10761076
if reso == 'year':
10771077
t1 = Timestamp(datetime(parsed.year, 1, 1), tz=self.tz)
1078-
t2 = Timestamp(datetime(parsed.year, 12, 31), tz=self.tz)
1078+
t2 = Timestamp(datetime(parsed.year, 12, 31, 23, 59, 59, 999999), tz=self.tz)
10791079
elif reso == 'month':
10801080
d = tslib.monthrange(parsed.year, parsed.month)[1]
10811081
t1 = Timestamp(datetime(parsed.year, parsed.month, 1), tz=self.tz)
1082-
t2 = Timestamp(datetime(parsed.year, parsed.month, d), tz=self.tz)
1082+
t2 = Timestamp(datetime(parsed.year, parsed.month, d, 23, 59, 59, 999999), tz=self.tz)
10831083
elif reso == 'quarter':
10841084
qe = (((parsed.month - 1) + 2) % 12) + 1 # two months ahead
10851085
d = tslib.monthrange(parsed.year, qe)[1] # at end of month
10861086
t1 = Timestamp(datetime(parsed.year, parsed.month, 1), tz=self.tz)
1087-
t2 = Timestamp(datetime(parsed.year, qe, d), tz=self.tz)
1087+
t2 = Timestamp(datetime(parsed.year, qe, d, 23, 59, 59, 999999), tz=self.tz)
10881088
elif (reso == 'day' and (self._resolution < Resolution.RESO_DAY or not is_monotonic)):
10891089
st = datetime(parsed.year, parsed.month, parsed.day)
10901090
t1 = Timestamp(st, tz=self.tz)

pandas/tseries/tests/test_timeseries.py

+16
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ def test_indexing(self):
236236
result = df['2001']['A']
237237
assert_series_equal(expected,result)
238238

239+
# GH3546 (not including times on the last day)
240+
idx = date_range(start='2013-05-31 00:00', end='2013-05-31 23:00', freq='H')
241+
ts = Series(range(len(idx)), index=idx)
242+
expected = ts['2013-05']
243+
assert_series_equal(expected,ts)
244+
245+
idx = date_range(start='2013-05-31 00:00', end='2013-05-31 23:59', freq='S')
246+
ts = Series(range(len(idx)), index=idx)
247+
expected = ts['2013-05']
248+
assert_series_equal(expected,ts)
249+
250+
idx = [ Timestamp('2013-05-31 00:00'), Timestamp(datetime(2013,5,31,23,59,59,999999))]
251+
ts = Series(range(len(idx)), index=idx)
252+
expected = ts['2013']
253+
assert_series_equal(expected,ts)
254+
239255
def assert_range_equal(left, right):
240256
assert(left.equals(right))
241257
assert(left.freq == right.freq)

0 commit comments

Comments
 (0)