Skip to content

Sync Fork from Upstream Repo #83

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 4 commits into from
Mar 8, 2020
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
20 changes: 15 additions & 5 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,6 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
-k"-nonzero -reindex -searchsorted -to_dict"
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests generic.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/generic.py \
-k"-_set_axis_name -_xs -describe -groupby -interpolate -pct_change -pipe -reindex -reindex_axis -to_json -transpose -values -xs -to_clipboard"
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests groupby.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/groupby/groupby.py -k"-cumcount -describe -pipe"
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down Expand Up @@ -311,6 +306,17 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
pytest -q --doctest-modules pandas/core/arrays/boolean.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests base.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/base.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests construction.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/construction.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests generic.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/generic.py
RET=$(($RET + $?)) ; echo $MSG "DONE"
fi

### DOCSTRINGS ###
Expand All @@ -320,6 +326,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL03,GL04,GL05,GL06,GL07,GL09,GL10,SS04,SS05,PR03,PR04,PR05,PR10,EX04,RT01,RT04,RT05,SA02,SA03,SA05
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Validate correct capitalization among titles in documentation' ; echo $MSG
$BASE_DIR/scripts/validate_rst_title_capitalization.py $BASE_DIR/doc/source/development/contributing.rst
RET=$(($RET + $?)) ; echo $MSG "DONE"

fi

### DEPENDENCIES ###
Expand Down
14 changes: 7 additions & 7 deletions doc/source/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ requires a C compiler and Python environment. If you're making documentation
changes, you can skip to :ref:`contributing.documentation` but you won't be able
to build the documentation locally before pushing your changes.

Using a Docker Container
Using a Docker container
~~~~~~~~~~~~~~~~~~~~~~~~

Instead of manually setting up a development environment, you can use Docker to
Expand Down Expand Up @@ -754,7 +754,7 @@ You can then verify the changes look ok, then git :ref:`commit <contributing.com

.. _contributing.pre-commit:

Pre-Commit
Pre-commit
~~~~~~~~~~

You can run many of these styling checks manually as we have described above. However,
Expand Down Expand Up @@ -822,12 +822,12 @@ See :ref:`contributing.warnings` for more.

.. _contributing.type_hints:

Type Hints
Type hints
----------

*pandas* strongly encourages the use of :pep:`484` style type hints. New development should contain type hints and pull requests to annotate existing code are accepted as well!

Style Guidelines
Style guidelines
~~~~~~~~~~~~~~~~

Types imports should follow the ``from typing import ...`` convention. So rather than
Expand Down Expand Up @@ -903,7 +903,7 @@ The limitation here is that while a human can reasonably understand that ``is_nu

With custom types and inference this is not always possible so exceptions are made, but every effort should be exhausted to avoid ``cast`` before going down such paths.

Pandas-specific Types
pandas-specific types
~~~~~~~~~~~~~~~~~~~~~

Commonly used types specific to *pandas* will appear in `pandas._typing <https://github.com/pandas-dev/pandas/blob/master/pandas/_typing.py>`_ and you should use these where applicable. This module is private for now but ultimately this should be exposed to third party libraries who want to implement type checking against pandas.
Expand All @@ -919,7 +919,7 @@ For example, quite a few functions in *pandas* accept a ``dtype`` argument. This

This module will ultimately house types for repeatedly used concepts like "path-like", "array-like", "numeric", etc... and can also hold aliases for commonly appearing parameters like `axis`. Development of this module is active so be sure to refer to the source for the most up to date list of available types.

Validating Type Hints
Validating type hints
~~~~~~~~~~~~~~~~~~~~~

*pandas* uses `mypy <http://mypy-lang.org>`_ to statically analyze the code base and type hints. After making any change you can ensure your type hints are correct by running
Expand Down Expand Up @@ -1539,7 +1539,7 @@ The branch will still exist on GitHub, so to delete it there do::
.. _Gitter: https://gitter.im/pydata/pandas


Tips for a successful Pull Request
Tips for a successful pull request
==================================

If you have made it to the `Review your code`_ phase, one of the core contributors may
Expand Down
32 changes: 20 additions & 12 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,41 +1473,49 @@ def factorize(self, sort=False, na_sentinel=-1):

Examples
--------
>>> x = pd.Series([1, 2, 3])
>>> x
>>> ser = pd.Series([1, 2, 3])
>>> ser
0 1
1 2
2 3
dtype: int64

>>> x.searchsorted(4)
>>> ser.searchsorted(4)
3

>>> x.searchsorted([0, 4])
>>> ser.searchsorted([0, 4])
array([0, 3])

>>> x.searchsorted([1, 3], side='left')
>>> ser.searchsorted([1, 3], side='left')
array([0, 2])

>>> x.searchsorted([1, 3], side='right')
>>> ser.searchsorted([1, 3], side='right')
array([1, 3])

>>> x = pd.Categorical(['apple', 'bread', 'bread',
'cheese', 'milk'], ordered=True)
>>> ser = pd.Categorical(
... ['apple', 'bread', 'bread', 'cheese', 'milk'], ordered=True
... )
>>> ser
[apple, bread, bread, cheese, milk]
Categories (4, object): [apple < bread < cheese < milk]

>>> x.searchsorted('bread')
>>> ser.searchsorted('bread')
1

>>> x.searchsorted(['bread'], side='right')
>>> ser.searchsorted(['bread'], side='right')
array([3])

If the values are not monotonically sorted, wrong locations
may be returned:

>>> x = pd.Series([2, 1, 3])
>>> x.searchsorted(1)
>>> ser = pd.Series([2, 1, 3])
>>> ser
0 2
1 1
2 3
dtype: int64

>>> ser.searchsorted(1) # doctest: +SKIP
0 # wrong result, correct would be 1
"""

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

These should not depend on core.internals.
"""

from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast

import numpy as np
Expand Down Expand Up @@ -200,12 +201,12 @@ def array(

>>> pd.array([1, 2, np.nan])
<IntegerArray>
[1, 2, NaN]
[1, 2, <NA>]
Length: 3, dtype: Int64

>>> pd.array(["a", None, "c"])
<StringArray>
['a', nan, 'c']
['a', <NA>, 'c']
Length: 3, dtype: string

>>> pd.array([pd.Period('2000', freq="D"), pd.Period("2000", freq="D")])
Expand Down
Loading