Skip to content

Commit 5c35c8d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into unique_reverse
2 parents 6e005c2 + 1a798be commit 5c35c8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1052
-446
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ dist
6262
coverage.xml
6363
coverage_html_report
6464
*.pytest_cache
65+
# hypothesis test database
66+
.hypothesis/
6567

6668
# OS generated files #
6769
######################

ci/appveyor-27.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ dependencies:
2828
- pytest
2929
- pytest-xdist
3030
- moto
31+
- hypothesis>=3.58.0

ci/appveyor-36.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ dependencies:
2525
- cython>=0.28.2
2626
- pytest
2727
- pytest-xdist
28+
- hypothesis>=3.58.0

ci/check_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'html5lib',
1010
'ipython',
1111
'jinja2'
12+
'hypothesis',
1213
'lxml',
1314
'numexpr',
1415
'openpyxl',

ci/circle-27-compat.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
- cython=0.28.2
88
- jinja2=2.8
99
- numexpr=2.4.4 # we test that we correctly don't use an unsupported numexpr
10-
- numpy=1.9.2
10+
- numpy=1.9.3
1111
- openpyxl
1212
- psycopg2
1313
- pytables=3.2.2
@@ -26,3 +26,4 @@ dependencies:
2626
- html5lib==1.0b2
2727
- beautifulsoup4==4.2.1
2828
- pymysql==0.6.0
29+
- hypothesis>=3.58.0

ci/circle-35-ascii.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ dependencies:
1111
# universal
1212
- pytest
1313
- pytest-xdist
14+
- pip:
15+
- hypothesis>=3.58.0

ci/circle-36-locale.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ dependencies:
3131
- pytest
3232
- pytest-xdist
3333
- moto
34+
- pip:
35+
- hypothesis>=3.58.0

ci/circle-36-locale_slow.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ dependencies:
3232
- pytest
3333
- pytest-xdist
3434
- moto
35+
- pip:
36+
- hypothesis>=3.58.0

ci/doctests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [ "$DOCTEST" ]; then
2828
fi
2929

3030
pytest --doctest-modules -v pandas/core/series.py \
31-
-k"-agg -map -nlargest -nonzero -nsmallest -reindex -searchsorted -to_dict"
31+
-k"-nlargest -nonzero -nsmallest -reindex -searchsorted -to_dict"
3232

3333
if [ $? -ne "0" ]; then
3434
RET=1

ci/environment-dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies:
77
- NumPy
88
- flake8
99
- flake8-comprehensions
10+
- hypothesis>=3.58.0
1011
- moto
1112
- pytest>=3.6
1213
- python-dateutil>=2.5.0

ci/requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Cython>=0.28.2
44
NumPy
55
flake8
66
flake8-comprehensions
7+
hypothesis>=3.58.0
78
moto
89
pytest>=3.6
910
python-dateutil>=2.5.0

ci/travis-27-locale.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
- cython=0.28.2
88
- lxml
99
- matplotlib=1.4.3
10-
- numpy=1.9.2
10+
- numpy=1.9.3
1111
- openpyxl=2.4.0
1212
- python-dateutil
1313
- python-blosc
@@ -22,6 +22,7 @@ dependencies:
2222
# universal
2323
- pytest
2424
- pytest-xdist
25+
- hypothesis>=3.58.0
2526
- pip:
2627
- html5lib==1.0b2
2728
- beautifulsoup4==4.2.1

ci/travis-27.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies:
4545
- pytest
4646
- pytest-xdist
4747
- moto
48+
- hypothesis>=3.58.0
4849
- pip:
4950
- backports.lzma
5051
- cpplint

ci/travis-35-osx.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ dependencies:
2525
- pytest-xdist
2626
- pip:
2727
- python-dateutil==2.5.3
28+
- hypothesis>=3.58.0

ci/travis-36-doc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
- fastparquet
1111
- feather-format
1212
- html5lib
13+
- hypothesis>=3.58.0
1314
- ipykernel
1415
- ipython
1516
- ipywidgets

ci/travis-36-numpydev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies:
88
# universal
99
- pytest
1010
- pytest-xdist
11+
- hypothesis>=3.58.0
1112
- pip:
1213
- "git+git://github.com/dateutil/dateutil.git"
1314
- "-f https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com"

ci/travis-36-slow.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ dependencies:
2828
- pytest
2929
- pytest-xdist
3030
- moto
31+
- hypothesis>=3.58.0

ci/travis-36.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies:
4141
- pytest-xdist
4242
- pytest-cov
4343
- moto
44+
- hypothesis>=3.58.0
4445
- pip:
4546
- brotlipy
4647
- coverage

ci/travis-37.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ dependencies:
1212
- pytz
1313
- pytest
1414
- pytest-xdist
15+
- hypothesis>=3.58.0

doc/source/contributing.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,46 @@ Tests that we have ``parametrized`` are now accessible via the test name, for ex
820820
test_cool_feature.py::test_series[int8] PASSED
821821
822822
823+
.. _using-hypothesis:
824+
825+
Using ``hypothesis``
826+
~~~~~~~~~~~~~~~~~~~~
827+
828+
Hypothesis is a library for property-based testing. Instead of explicitly
829+
parametrizing a test, you can describe *all* valid inputs and let Hypothesis
830+
try to find a failing input. Even better, no matter how many random examples
831+
it tries, Hypothesis always reports a single minimal counterexample to your
832+
assertions - often an example that you would never have thought to test.
833+
834+
See `Getting Started with Hypothesis <https://hypothesis.works/articles/getting-started-with-hypothesis/>`_
835+
for more of an introduction, then `refer to the Hypothesis documentation
836+
for details <https://hypothesis.readthedocs.io/en/latest/index.html>`_.
837+
838+
.. code-block:: python
839+
840+
import json
841+
from hypothesis import given, strategies as st
842+
843+
any_json_value = st.deferred(lambda: st.one_of(
844+
st.none(), st.booleans(), st.floats(allow_nan=False), st.text(),
845+
st.lists(any_json_value), st.dictionaries(st.text(), any_json_value)
846+
))
847+
848+
@given(value=any_json_value)
849+
def test_json_roundtrip(value):
850+
result = json.loads(json.dumps(value))
851+
assert value == result
852+
853+
This test shows off several useful features of Hypothesis, as well as
854+
demonstrating a good use-case: checking properties that should hold over
855+
a large or complicated domain of inputs.
856+
857+
To keep the Pandas test suite running quickly, parametrized tests are
858+
preferred if the inputs or logic are simple, with Hypothesis tests reserved
859+
for cases with complex logic or where there are too many combinations of
860+
options or subtle interactions to test (or think of!) all of them.
861+
862+
823863
Running the test suite
824864
----------------------
825865

doc/source/groupby.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ consider the following ``DataFrame``:
103103

104104
.. note::
105105

106-
.. versionadded:: 0.20
107-
108106
A string passed to ``groupby`` may refer to either a column or an index level.
109107
If a string matches both a column name and an index level name, a
110108
``ValueError`` will be raised.

doc/source/install.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ pandas is equipped with an exhaustive set of unit tests, covering about 97% of
202202
the code base as of this writing. To run it on your machine to verify that
203203
everything is working (and that you have all of the dependencies, soft and hard,
204204
installed), make sure you have `pytest
205-
<http://docs.pytest.org/en/latest/>`__ >= 3.6 and run:
205+
<http://docs.pytest.org/en/latest/>`__ >= 3.6 and `Hypothesis
206+
<https://hypothesis.readthedocs.io/>`__ >= 3.58, then run:
206207

207208
::
208209

doc/source/whatsnew/v0.24.0.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ without timezone localization. This is inconsistent from parsing the same
285285
datetime string with :class:`Timestamp` which would preserve the UTC
286286
offset in the ``tz`` attribute. Now, :func:`to_datetime` preserves the UTC
287287
offset in the ``tz`` attribute when all the datetime strings have the same
288-
UTC offset (:issue:`17697`, :issue:`11736`)
288+
UTC offset (:issue:`17697`, :issue:`11736`, :issue:`22457`)
289289

290290
*Previous Behavior*:
291291

@@ -493,6 +493,7 @@ ExtensionType Changes
493493
- Added ``ExtensionDtype._is_numeric`` for controlling whether an extension dtype is considered numeric (:issue:`22290`).
494494
- The ``ExtensionArray`` constructor, ``_from_sequence`` now take the keyword arg ``copy=False`` (:issue:`21185`)
495495
- Bug in :meth:`Series.get` for ``Series`` using ``ExtensionArray`` and integer index (:issue:`21257`)
496+
- :meth:`~Series.shift` now dispatches to :meth:`ExtensionArray.shift` (:issue:`22386`)
496497
- :meth:`Series.combine()` works correctly with :class:`~pandas.api.extensions.ExtensionArray` inside of :class:`Series` (:issue:`20825`)
497498
- :meth:`Series.combine()` with scalar argument now works for any function type (:issue:`21248`)
498499
- :meth:`Series.astype` and :meth:`DataFrame.astype` now dispatch to :meth:`ExtensionArray.astype` (:issue:`21185:`).
@@ -627,12 +628,14 @@ Datetimelike
627628
- Bug in :class:`DataFrame` comparisons against ``Timestamp``-like objects failing to raise ``TypeError`` for inequality checks with mismatched types (:issue:`8932`,:issue:`22163`)
628629
- Bug in :class:`DataFrame` with mixed dtypes including ``datetime64[ns]`` incorrectly raising ``TypeError`` on equality comparisons (:issue:`13128`,:issue:`22163`)
629630
- Bug in :meth:`DataFrame.eq` comparison against ``NaT`` incorrectly returning ``True`` or ``NaN`` (:issue:`15697`,:issue:`22163`)
630-
- Bug in :class:`DataFrame` with ``timedelta64[ns]`` dtype division by ``Timedelta``-like scalar incorrectly returning ``timedelta64[ns]`` dtype instead of ``float64`` dtype (:issue:`20088`,:issue:`22163`)
631-
-
632631

633632
Timedelta
634633
^^^^^^^^^
635-
634+
- Bug in :class:`DataFrame` with ``timedelta64[ns]`` dtype division by ``Timedelta``-like scalar incorrectly returning ``timedelta64[ns]`` dtype instead of ``float64`` dtype (:issue:`20088`,:issue:`22163`)
635+
- Bug in adding a :class:`Index` with object dtype to a :class:`Series` with ``timedelta64[ns]`` dtype incorrectly raising (:issue:`22390`)
636+
- Bug in multiplying a :class:`Series` with numeric dtype against a ``timedelta`` object (:issue:`22390`)
637+
- Bug in :class:`Series` with numeric dtype when adding or subtracting an an array or ``Series`` with ``timedelta64`` dtype (:issue:`22390`)
638+
- Bug in :class:`Index` with numeric dtype when multiplying or dividing an array with dtype ``timedelta64`` (:issue:`22390`)
636639
-
637640
-
638641
-
@@ -677,6 +680,7 @@ Numeric
677680
a ``TypeError`` was wrongly raised. For all three methods such calculation are now done correctly. (:issue:`16679`).
678681
- Bug in :class:`Series` comparison against datetime-like scalars and arrays (:issue:`22074`)
679682
- Bug in :class:`DataFrame` multiplication between boolean dtype and integer returning ``object`` dtype instead of integer dtype (:issue:`22047`,:issue:`22163`)
683+
- Bug in :meth:`DataFrame.apply` where, when supplied with a string argument and additional positional or keyword arguments (e.g. ``df.apply('sum', min_count=1)``), a ``TypeError`` was wrongly raised (:issue:`22376`)
680684
-
681685

682686
Strings
@@ -705,6 +709,7 @@ Indexing
705709
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`)
706710
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
707711
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`)
712+
- Bug where mixed indexes wouldn't allow integers for ``.at`` (:issue:`19860`)
708713
- ``Float64Index.get_loc`` now raises ``KeyError`` when boolean key passed. (:issue:`19087`)
709714

710715
Missing
@@ -765,20 +770,22 @@ Reshaping
765770
- Bug in :func:`get_dummies` with Unicode attributes in Python 2 (:issue:`22084`)
766771
- Bug in :meth:`DataFrame.replace` raises ``RecursionError`` when replacing empty lists (:issue:`22083`)
767772
- Bug in :meth:`Series.replace` and meth:`DataFrame.replace` when dict is used as the `to_replace` value and one key in the dict is is another key's value, the results were inconsistent between using integer key and using string key (:issue:`20656`)
768-
-
773+
- Bug in :meth:`DataFrame.drop_duplicates` for empty ``DataFrame`` which incorrectly raises an error (:issue:`20516`)
769774

770775
Build Changes
771776
^^^^^^^^^^^^^
772777

773778
- Building pandas for development now requires ``cython >= 0.28.2`` (:issue:`21688`)
779+
- Testing pandas now requires ``hypothesis>=3.58`` (:issue:22280). You can find `the Hypothesis docs here <https://hypothesis.readthedocs.io/en/latest/index.html>`_, and a pandas-specific introduction :ref:`in the contributing guide <using-hypothesis>` .
774780
-
775781

776782
Other
777783
^^^^^
778784

779-
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
785+
- :meth:`~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
780786
- Require at least 0.28.2 version of ``cython`` to support read-only memoryviews (:issue:`21688`)
781-
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
787+
- :meth:`~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
788+
- :meth:`~pandas.io.formats.style.Styler.bar` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` and setting clipping range with ``vmin`` and ``vmax`` (:issue:`21548` and :issue:`21526`). ``NaN`` values are also handled properly.
782789
-
783790
-
784791
-

pandas/_libs/index.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ cdef class IndexEngine:
104104
loc = self.get_loc(key)
105105
value = convert_scalar(arr, value)
106106

107-
if PySlice_Check(loc) or util.is_array(loc):
108-
arr[loc] = value
109-
else:
110-
util.set_value_at(arr, loc, value)
107+
arr[loc] = value
111108

112109
cpdef get_loc(self, object val):
113110
if is_definitely_invalid_key(val):

pandas/_libs/lib.pyx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,7 @@ def astype_intsafe(ndarray[object] arr, new_dtype):
492492
if is_datelike and checknull(v):
493493
result[i] = NPY_NAT
494494
else:
495-
# we can use the unsafe version because we know `result` is mutable
496-
# since it was created from `np.empty`
497-
util.set_value_at_unsafe(result, i, v)
495+
result[i] = v
498496

499497
return result
500498

@@ -505,9 +503,7 @@ cpdef ndarray[object] astype_unicode(ndarray arr):
505503
ndarray[object] result = np.empty(n, dtype=object)
506504

507505
for i in range(n):
508-
# we can use the unsafe version because we know `result` is mutable
509-
# since it was created from `np.empty`
510-
util.set_value_at_unsafe(result, i, unicode(arr[i]))
506+
result[i] = unicode(arr[i])
511507

512508
return result
513509

@@ -518,9 +514,7 @@ cpdef ndarray[object] astype_str(ndarray arr):
518514
ndarray[object] result = np.empty(n, dtype=object)
519515

520516
for i in range(n):
521-
# we can use the unsafe version because we know `result` is mutable
522-
# since it was created from `np.empty`
523-
util.set_value_at_unsafe(result, i, str(arr[i]))
517+
result[i] = str(arr[i])
524518

525519
return result
526520

pandas/_libs/reduction.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ cnp.import_array()
1818
cimport util
1919
from lib import maybe_convert_objects
2020

21-
is_numpy_prior_1_6_2 = LooseVersion(np.__version__) < '1.6.2'
22-
2321

2422
cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt):
2523

@@ -282,8 +280,7 @@ cdef class SeriesBinGrouper:
282280
result = _get_result_array(res,
283281
self.ngroups,
284282
len(self.dummy_arr))
285-
286-
util.assign_value_1d(result, i, res)
283+
result[i] = res
287284

288285
islider.advance(group_size)
289286
vslider.advance(group_size)
@@ -408,7 +405,7 @@ cdef class SeriesGrouper:
408405
self.ngroups,
409406
len(self.dummy_arr))
410407

411-
util.assign_value_1d(result, lab, res)
408+
result[lab] = res
412409
counts[lab] = group_size
413410
islider.advance(group_size)
414411
vslider.advance(group_size)

pandas/_libs/src/numpy_helper.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)