Skip to content

Commit d79a39c

Browse files
Merge branch 'master' into issue_24980
2 parents 4932ff0 + 5d1e633 commit d79a39c

File tree

13 files changed

+85
-41
lines changed

13 files changed

+85
-41
lines changed

.github/CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ Our main contributing guide can be found [in this repo](https://github.com/panda
88

99
If you are looking to contribute to the *pandas* codebase, the best place to start is the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues). This is also a great place for filing bug reports and making suggestions for ways in which we can improve the code and documentation.
1010

11-
If you have additional questions, feel free to ask them on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas). Further information can also be found in the "[Where to start?](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#where-to-start)" section.
11+
If you have additional questions, feel free to ask them on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas). Further information can also be found in the "[Where to start?](https://github.com/pandas-dev/pandas/blob/master/doc/source/development/contributing.rst#where-to-start)" section.
1212

1313
## Filing Issues
1414

15-
If you notice a bug in the code or documentation, or have suggestions for how we can improve either, feel free to create an issue on the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) using [GitHub's "issue" form](https://github.com/pandas-dev/pandas/issues/new). The form contains some questions that will help us best address your issue. For more information regarding how to file issues against *pandas*, please refer to the "[Bug reports and enhancement requests](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#bug-reports-and-enhancement-requests)" section.
15+
If you notice a bug in the code or documentation, or have suggestions for how we can improve either, feel free to create an issue on the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) using [GitHub's "issue" form](https://github.com/pandas-dev/pandas/issues/new). The form contains some questions that will help us best address your issue. For more information regarding how to file issues against *pandas*, please refer to the "[Bug reports and enhancement requests](https://github.com/pandas-dev/pandas/blob/master/doc/source/development/contributing.rst#bug-reports-and-enhancement-requests)" section.
1616

1717
## Contributing to the Codebase
1818

19-
The code is hosted on [GitHub](https://www.github.com/pandas-dev/pandas), so you will need to use [Git](http://git-scm.com/) to clone the project and make changes to the codebase. Once you have obtained a copy of the code, you should create a development environment that is separate from your existing Python environment so that you can make and test changes without compromising your own work environment. For more information, please refer to the "[Working with the code](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#working-with-the-code)" section.
19+
The code is hosted on [GitHub](https://www.github.com/pandas-dev/pandas), so you will need to use [Git](http://git-scm.com/) to clone the project and make changes to the codebase. Once you have obtained a copy of the code, you should create a development environment that is separate from your existing Python environment so that you can make and test changes without compromising your own work environment. For more information, please refer to the "[Working with the code](https://github.com/pandas-dev/pandas/blob/master/doc/source/development/contributing.rst#working-with-the-code)" section.
2020

21-
Before submitting your changes for review, make sure to check that your changes do not break any tests. You can find more information about our test suites in the "[Test-driven development/code writing](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#test-driven-development-code-writing)" section. We also have guidelines regarding coding style that will be enforced during testing, which can be found in the "[Code standards](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#code-standards)" section.
21+
Before submitting your changes for review, make sure to check that your changes do not break any tests. You can find more information about our test suites in the "[Test-driven development/code writing](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#test-driven-development-code-writing)" section. We also have guidelines regarding coding style that will be enforced during testing, which can be found in the "[Code standards](https://github.com/pandas-dev/pandas/blob/master/doc/source/development/contributing.rst#code-standards)" section.
2222

23-
Once your changes are ready to be submitted, make sure to push your changes to GitHub before creating a pull request. Details about how to do that can be found in the "[Contributing your changes to pandas](https://github.com/pandas-dev/pandas/blob/master/doc/source/contributing.rst#contributing-your-changes-to-pandas)" section. We will review your changes, and you will most likely be asked to make additional changes before it is finally ready to merge. However, once it's ready, we will merge it, and you will have successfully contributed to the codebase!
23+
Once your changes are ready to be submitted, make sure to push your changes to GitHub before creating a pull request. Details about how to do that can be found in the "[Contributing your changes to pandas](https://github.com/pandas-dev/pandas/blob/master/doc/source/development/contributing.rst#contributing-your-changes-to-pandas)" section. We will review your changes, and you will most likely be asked to make additional changes before it is finally ready to merge. However, once it's ready, we will merge it, and you will have successfully contributed to the codebase!

asv_bench/benchmarks/algorithms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pandas as pd
66
from pandas.util import testing as tm
77

8-
98
for imp in ['pandas.util', 'pandas.tools.hashing']:
109
try:
1110
hashing = import_module(imp)
@@ -142,4 +141,4 @@ def time_quantile(self, quantile, interpolation, dtype):
142141
self.idx.quantile(quantile, interpolation=interpolation)
143142

144143

145-
from .pandas_vb_common import setup # noqa: F401
144+
from .pandas_vb_common import setup # noqa: F401 isort:skip

asv_bench/benchmarks/strings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def setup(self, repeats):
102102
N = 10**5
103103
self.s = Series(tm.makeStringIndex(N))
104104
repeat = {'int': 1, 'array': np.random.randint(1, 3, N)}
105-
self.repeat = repeat[repeats]
105+
self.values = repeat[repeats]
106106

107107
def time_repeat(self, repeats):
108-
self.s.str.repeat(self.repeat)
108+
self.s.str.repeat(self.values)
109109

110110

111111
class Cat(object):

doc/source/whatsnew/v0.24.1.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fixed Regressions
2323
- Bug in :meth:`DataFrame.itertuples` with ``records`` orient raising an ``AttributeError`` when the ``DataFrame`` contained more than 255 columns (:issue:`24939`)
2424
- Bug in :meth:`DataFrame.itertuples` orient converting integer column names to strings prepended with an underscore (:issue:`24940`)
2525
- Bug in :meth:`to_string` with ``index`` set to ``False``, leading space is added. (:issue:`24980`)
26+
- Fixed regression in :class:`Index.intersection` incorrectly sorting the values by default (:issue:`24959`).
2627

2728
.. _whatsnew_0241.enhancements:
2829

@@ -73,8 +74,7 @@ Bug Fixes
7374

7475
**Reshaping**
7576

76-
-
77-
-
77+
- Bug in :meth:`DataFrame.groupby` with :class:`Grouper` when there is a time change (DST) and grouping frequency is ``'1d'`` (:issue:`24972`)
7878

7979
**Visualization**
8080

pandas/core/indexes/base.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ def union(self, other, sort=True):
23332333
def _wrap_setop_result(self, other, result):
23342334
return self._constructor(result, name=get_op_result_name(self, other))
23352335

2336-
def intersection(self, other, sort=True):
2336+
def intersection(self, other, sort=False):
23372337
"""
23382338
Form the intersection of two Index objects.
23392339
@@ -2342,11 +2342,15 @@ def intersection(self, other, sort=True):
23422342
Parameters
23432343
----------
23442344
other : Index or array-like
2345-
sort : bool, default True
2345+
sort : bool, default False
23462346
Sort the resulting index if possible
23472347
23482348
.. versionadded:: 0.24.0
23492349
2350+
.. versionchanged:: 0.24.1
2351+
2352+
Changed the default from ``True`` to ``False``.
2353+
23502354
Returns
23512355
-------
23522356
intersection : Index

pandas/core/indexes/datetimes.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,22 @@ def _wrap_setop_result(self, other, result):
594594
name = get_op_result_name(self, other)
595595
return self._shallow_copy(result, name=name, freq=None, tz=self.tz)
596596

597-
def intersection(self, other, sort=True):
597+
def intersection(self, other, sort=False):
598598
"""
599599
Specialized intersection for DatetimeIndex objects. May be much faster
600600
than Index.intersection
601601
602602
Parameters
603603
----------
604604
other : DatetimeIndex or array-like
605+
sort : bool, default True
606+
Sort the resulting index if possible.
607+
608+
.. versionadded:: 0.24.0
609+
610+
.. versionchanged:: 0.24.1
611+
612+
Changed the default from ``True`` to ``False``.
605613
606614
Returns
607615
-------

pandas/core/indexes/interval.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,8 @@ def equals(self, other):
10931093
def overlaps(self, other):
10941094
return self._data.overlaps(other)
10951095

1096-
def _setop(op_name):
1097-
def func(self, other, sort=True):
1096+
def _setop(op_name, sort=True):
1097+
def func(self, other, sort=sort):
10981098
other = self._as_like_interval_index(other)
10991099

11001100
# GH 19016: ensure set op will not return a prohibited dtype
@@ -1128,7 +1128,7 @@ def is_all_dates(self):
11281128
return False
11291129

11301130
union = _setop('union')
1131-
intersection = _setop('intersection')
1131+
intersection = _setop('intersection', sort=False)
11321132
difference = _setop('difference')
11331133
symmetric_difference = _setop('symmetric_difference')
11341134

pandas/core/indexes/multi.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2910,7 +2910,7 @@ def union(self, other, sort=True):
29102910
return MultiIndex.from_arrays(lzip(*uniq_tuples), sortorder=0,
29112911
names=result_names)
29122912

2913-
def intersection(self, other, sort=True):
2913+
def intersection(self, other, sort=False):
29142914
"""
29152915
Form the intersection of two MultiIndex objects.
29162916
@@ -2922,6 +2922,10 @@ def intersection(self, other, sort=True):
29222922
29232923
.. versionadded:: 0.24.0
29242924
2925+
.. versionchanged:: 0.24.1
2926+
2927+
Changed the default from ``True`` to ``False``.
2928+
29252929
Returns
29262930
-------
29272931
Index

pandas/core/indexes/range.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def equals(self, other):
343343

344344
return super(RangeIndex, self).equals(other)
345345

346-
def intersection(self, other, sort=True):
346+
def intersection(self, other, sort=False):
347347
"""
348348
Form the intersection of two Index objects.
349349
@@ -355,6 +355,10 @@ def intersection(self, other, sort=True):
355355
356356
.. versionadded:: 0.24.0
357357
358+
.. versionchanged:: 0.24.1
359+
360+
Changed the default from ``True`` to ``False``.
361+
358362
Returns
359363
-------
360364
intersection : Index

pandas/core/resample.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
from pandas.core.indexes.timedeltas import TimedeltaIndex, timedelta_range
3131

3232
from pandas.tseries.frequencies import to_offset
33-
from pandas.tseries.offsets import (
34-
DateOffset, Day, Nano, Tick, delta_to_nanoseconds)
33+
from pandas.tseries.offsets import DateOffset, Day, Nano, Tick
3534

3635
_shared_docs_kwargs = dict()
3736

@@ -1613,20 +1612,20 @@ def _get_timestamp_range_edges(first, last, offset, closed='left', base=0):
16131612
A tuple of length 2, containing the adjusted pd.Timestamp objects.
16141613
"""
16151614
if isinstance(offset, Tick):
1616-
is_day = isinstance(offset, Day)
1617-
day_nanos = delta_to_nanoseconds(timedelta(1))
1618-
1619-
# #1165 and #24127
1620-
if (is_day and not offset.nanos % day_nanos) or not is_day:
1621-
first, last = _adjust_dates_anchored(first, last, offset,
1622-
closed=closed, base=base)
1623-
if is_day and first.tz is not None:
1624-
# _adjust_dates_anchored assumes 'D' means 24H, but first/last
1625-
# might contain a DST transition (23H, 24H, or 25H).
1626-
# Ensure first/last snap to midnight.
1627-
first = first.normalize()
1628-
last = last.normalize()
1629-
return first, last
1615+
if isinstance(offset, Day):
1616+
# _adjust_dates_anchored assumes 'D' means 24H, but first/last
1617+
# might contain a DST transition (23H, 24H, or 25H).
1618+
# So "pretend" the dates are naive when adjusting the endpoints
1619+
tz = first.tz
1620+
first = first.tz_localize(None)
1621+
last = last.tz_localize(None)
1622+
1623+
first, last = _adjust_dates_anchored(first, last, offset,
1624+
closed=closed, base=base)
1625+
if isinstance(offset, Day):
1626+
first = first.tz_localize(tz)
1627+
last = last.tz_localize(tz)
1628+
return first, last
16301629

16311630
else:
16321631
first = first.normalize()

pandas/tests/indexes/test_base.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ def test_intersect_str_dates(self, sort):
765765

766766
assert len(result) == 0
767767

768+
def test_intersect_nosort(self):
769+
result = pd.Index(['c', 'b', 'a']).intersection(['b', 'a'])
770+
expected = pd.Index(['b', 'a'])
771+
tm.assert_index_equal(result, expected)
772+
768773
@pytest.mark.parametrize("sort", [True, False])
769774
def test_chained_union(self, sort):
770775
# Chained unions handles names correctly
@@ -1595,20 +1600,27 @@ def test_drop_tuple(self, values, to_drop):
15951600
for drop_me in to_drop[1], [to_drop[1]]:
15961601
pytest.raises(KeyError, removed.drop, drop_me)
15971602

1598-
@pytest.mark.parametrize("method,expected", [
1603+
@pytest.mark.parametrize("method,expected,sort", [
1604+
('intersection', np.array([(1, 'A'), (2, 'A'), (1, 'B'), (2, 'B')],
1605+
dtype=[('num', int), ('let', 'a1')]),
1606+
False),
1607+
15991608
('intersection', np.array([(1, 'A'), (1, 'B'), (2, 'A'), (2, 'B')],
1600-
dtype=[('num', int), ('let', 'a1')])),
1609+
dtype=[('num', int), ('let', 'a1')]),
1610+
True),
1611+
16011612
('union', np.array([(1, 'A'), (1, 'B'), (1, 'C'), (2, 'A'), (2, 'B'),
1602-
(2, 'C')], dtype=[('num', int), ('let', 'a1')]))
1613+
(2, 'C')], dtype=[('num', int), ('let', 'a1')]),
1614+
True)
16031615
])
1604-
def test_tuple_union_bug(self, method, expected):
1616+
def test_tuple_union_bug(self, method, expected, sort):
16051617
index1 = Index(np.array([(1, 'A'), (2, 'A'), (1, 'B'), (2, 'B')],
16061618
dtype=[('num', int), ('let', 'a1')]))
16071619
index2 = Index(np.array([(1, 'A'), (2, 'A'), (1, 'B'),
16081620
(2, 'B'), (1, 'C'), (2, 'C')],
16091621
dtype=[('num', int), ('let', 'a1')]))
16101622

1611-
result = getattr(index1, method)(index2)
1623+
result = getattr(index1, method)(index2, sort=sort)
16121624
assert result.ndim == 1
16131625

16141626
expected = Index(expected)

pandas/tests/resample/test_datetime_index.py

+15
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,21 @@ def test_resample_across_dst():
12781278
assert_frame_equal(result, expected)
12791279

12801280

1281+
def test_groupby_with_dst_time_change():
1282+
# GH 24972
1283+
index = pd.DatetimeIndex([1478064900001000000, 1480037118776792000],
1284+
tz='UTC').tz_convert('America/Chicago')
1285+
1286+
df = pd.DataFrame([1, 2], index=index)
1287+
result = df.groupby(pd.Grouper(freq='1d')).last()
1288+
expected_index_values = pd.date_range('2016-11-02', '2016-11-24',
1289+
freq='d', tz='America/Chicago')
1290+
1291+
index = pd.DatetimeIndex(expected_index_values)
1292+
expected = pd.DataFrame([1.0] + ([np.nan] * 21) + [2.0], index=index)
1293+
assert_frame_equal(result, expected)
1294+
1295+
12811296
def test_resample_dst_anchor():
12821297
# 5172
12831298
dti = DatetimeIndex([datetime(2012, 11, 4, 23)], tz='US/Eastern')

setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ force_sort_within_sections=True
114114
skip=
115115
pandas/core/api.py,
116116
pandas/core/frame.py,
117-
asv_bench/benchmarks/algorithms.py,
118117
asv_bench/benchmarks/attrs_caching.py,
119118
asv_bench/benchmarks/binary_ops.py,
120119
asv_bench/benchmarks/categoricals.py,

0 commit comments

Comments
 (0)