Skip to content

Commit cc0fe3b

Browse files
Merge remote-tracking branch 'upstream/master' into GH10285
2 parents 6794a3c + b966657 commit cc0fe3b

File tree

327 files changed

+9899
-7777
lines changed

Some content is hidden

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

327 files changed

+9899
-7777
lines changed

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,42 @@ repos:
119119
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
120120
types: [python]
121121
exclude: ^(asv_bench|pandas/tests|doc)/
122+
- id: inconsistent-namespace-usage
123+
name: 'Check for inconsistent use of pandas namespace in tests'
124+
entry: python scripts/check_for_inconsistent_pandas_namespace.py
125+
language: python
126+
types: [python]
127+
files: ^pandas/tests/
128+
- id: FrameOrSeriesUnion
129+
name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
130+
entry: Union\[.*(Series.*DataFrame|DataFrame.*Series).*\]
131+
language: pygrep
132+
types: [python]
133+
exclude: ^pandas/_typing\.py$
134+
- id: type-not-class
135+
name: Check for use of foo.__class__ instead of type(foo)
136+
entry: \.__class__
137+
language: pygrep
138+
files: \.(py|pyx)$
139+
- id: unwanted-typing
140+
name: Check for use of comment-based annotation syntax and missing error codes
141+
entry: |
142+
(?x)
143+
\#\ type:\ (?!ignore)|
144+
\#\ type:\s?ignore(?!\[)
145+
language: pygrep
146+
types: [python]
147+
- id: no-os-remove
148+
name: Check code for instances of os.remove
149+
entry: os\.remove
150+
language: pygrep
151+
types: [python]
152+
files: ^pandas/tests/
153+
exclude: |
154+
(?x)^
155+
pandas/tests/io/excel/test_writers\.py|
156+
pandas/tests/io/pytables/common\.py|
157+
pandas/tests/io/pytables/test_store\.py$
122158
- repo: https://github.com/asottile/yesqa
123159
rev: v1.2.2
124160
hooks:

ci/code_checks.sh

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ function invgrep {
3737
return $((! $EXIT_STATUS))
3838
}
3939

40-
function check_namespace {
41-
local -r CLASS=${1}
42-
grep -R -l --include "*.py" " ${CLASS}(" pandas/tests | xargs grep -n "pd\.${CLASS}[(\.]"
43-
test $? -gt 0
44-
}
45-
4640
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
4741
FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
4842
INVGREP_PREPEND="##[error]"
@@ -120,36 +114,6 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
120114
MSG='Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
121115
invgrep -R --include=*.{py,pyx} '!r}' pandas
122116
RET=$(($RET + $?)) ; echo $MSG "DONE"
123-
124-
# -------------------------------------------------------------------------
125-
# Type annotations
126-
127-
MSG='Check for use of comment-based annotation syntax' ; echo $MSG
128-
invgrep -R --include="*.py" -P '# type: (?!ignore)' pandas
129-
RET=$(($RET + $?)) ; echo $MSG "DONE"
130-
131-
MSG='Check for missing error codes with # type: ignore' ; echo $MSG
132-
invgrep -R --include="*.py" -P '# type:\s?ignore(?!\[)' pandas
133-
RET=$(($RET + $?)) ; echo $MSG "DONE"
134-
135-
MSG='Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias' ; echo $MSG
136-
invgrep -R --include="*.py" --exclude=_typing.py -E 'Union\[.*(Series.*DataFrame|DataFrame.*Series).*\]' pandas
137-
RET=$(($RET + $?)) ; echo $MSG "DONE"
138-
139-
# -------------------------------------------------------------------------
140-
MSG='Check for use of foo.__class__ instead of type(foo)' ; echo $MSG
141-
invgrep -R --include=*.{py,pyx} '\.__class__' pandas
142-
RET=$(($RET + $?)) ; echo $MSG "DONE"
143-
144-
MSG='Check code for instances of os.remove' ; echo $MSG
145-
invgrep -R --include="*.py*" --exclude "common.py" --exclude "test_writers.py" --exclude "test_store.py" -E "os\.remove" pandas/tests/
146-
RET=$(($RET + $?)) ; echo $MSG "DONE"
147-
148-
MSG='Check for inconsistent use of pandas namespace in tests' ; echo $MSG
149-
for class in "Series" "DataFrame" "Index" "MultiIndex" "Timestamp" "Timedelta" "TimedeltaIndex" "DatetimeIndex" "Categorical"; do
150-
check_namespace ${class}
151-
RET=$(($RET + $?))
152-
done
153117
echo $MSG "DONE"
154118
fi
155119

@@ -261,8 +225,8 @@ fi
261225
### DOCSTRINGS ###
262226
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
263227

264-
MSG='Validate docstrings (GL03, GL04, GL05, GL06, GL07, GL09, GL10, SS04, SS05, PR03, PR04, PR05, PR10, EX04, RT01, RT04, RT05, SA02, SA03)' ; echo $MSG
265-
$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
228+
MSG='Validate docstrings (GL03, GL04, GL05, GL06, GL07, GL09, GL10, SS02, SS04, SS05, PR03, PR04, PR05, PR10, EX04, RT01, RT04, RT05, SA02, SA03)' ; echo $MSG
229+
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL03,GL04,GL05,GL06,GL07,GL09,GL10,SS02,SS04,SS05,PR03,PR04,PR05,PR10,EX04,RT01,RT04,RT05,SA02,SA03
266230
RET=$(($RET + $?)) ; echo $MSG "DONE"
267231

268232
MSG='Validate correct capitalization among titles in documentation' ; echo $MSG

doc/source/development/code_style.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ pandas code style guide
1212
pandas follows the `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_
1313
standard and uses `Black <https://black.readthedocs.io/en/stable/>`_
1414
and `Flake8 <https://flake8.pycqa.org/en/latest/>`_ to ensure a
15-
consistent code format throughout the project. For details see the
16-
:ref:`contributing guide to pandas<contributing.code-formatting>`.
15+
consistent code format throughout the project. We encourage you to use
16+
:ref:`pre-commit <contributing.pre-commit>` to automatically run ``black``,
17+
``flake8``, ``isort``, and related code checks when you make a git commit.
1718

1819
Patterns
1920
========

doc/source/development/contributing.rst

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,46 @@ In addition to ``./ci/code_checks.sh``, some extra checks are run by
638638
``pre-commit`` - see :ref:`here <contributing.pre-commit>` for how to
639639
run them.
640640

641-
Additional standards are outlined on the :ref:`pandas code style guide <code_style>`
641+
Additional standards are outlined on the :ref:`pandas code style guide <code_style>`.
642+
643+
.. _contributing.pre-commit:
644+
645+
Pre-commit
646+
----------
647+
648+
You can run many of these styling checks manually as we have described above. However,
649+
we encourage you to use `pre-commit hooks <https://pre-commit.com/>`_ instead
650+
to automatically run ``black``, ``flake8``, ``isort`` when you make a git commit. This
651+
can be done by installing ``pre-commit``::
652+
653+
pip install pre-commit
654+
655+
and then running::
656+
657+
pre-commit install
658+
659+
from the root of the pandas repository. Now all of the styling checks will be
660+
run each time you commit changes without your needing to run each one manually.
661+
In addition, using ``pre-commit`` will also allow you to more easily
662+
remain up-to-date with our code checks as they change.
663+
664+
Note that if needed, you can skip these checks with ``git commit --no-verify``.
665+
666+
If you don't want to use ``pre-commit`` as part of your workflow, you can still use it
667+
to run its checks with::
668+
669+
pre-commit run --files <files you have modified>
670+
671+
without needing to have done ``pre-commit install`` beforehand.
672+
673+
.. note::
674+
675+
If you have conflicting installations of ``virtualenv``, then you may get an
676+
error - see `here <https://github.com/pypa/virtualenv/issues/1875>`_.
677+
678+
Also, due to a `bug in virtualenv <https://github.com/pypa/virtualenv/issues/1986>`_,
679+
you may run into issues if you're using conda. To solve this, you can downgrade
680+
``virtualenv`` to version ``20.0.33``.
642681

643682
Optional dependencies
644683
---------------------
@@ -712,7 +751,7 @@ Python (PEP8 / black)
712751
pandas follows the `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ standard
713752
and uses `Black <https://black.readthedocs.io/en/stable/>`_ and
714753
`Flake8 <http://flake8.pycqa.org/en/latest/>`_ to ensure a consistent code
715-
format throughout the project.
754+
format throughout the project. We encourage you to use :ref:`pre-commit <contributing.pre-commit>`.
716755

717756
:ref:`Continuous Integration <contributing.ci>` will run those tools and
718757
report any stylistic errors in your code. Therefore, it is helpful before
@@ -727,9 +766,6 @@ apply ``black`` as you edit files.
727766
You should use a ``black`` version 20.8b1 as previous versions are not compatible
728767
with the pandas codebase.
729768

730-
If you wish to run these checks automatically, we encourage you to use
731-
:ref:`pre-commits <contributing.pre-commit>` instead.
732-
733769
One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this
734770
command will catch any stylistic errors in your changes specifically, but
735771
be beware it may not catch all of them. For example, if you delete the only
@@ -807,45 +843,6 @@ Where similar caveats apply if you are on OSX or Windows.
807843

808844
You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.
809845

810-
.. _contributing.pre-commit:
811-
812-
Pre-commit
813-
~~~~~~~~~~
814-
815-
You can run many of these styling checks manually as we have described above. However,
816-
we encourage you to use `pre-commit hooks <https://pre-commit.com/>`_ instead
817-
to automatically run ``black``, ``flake8``, ``isort`` when you make a git commit. This
818-
can be done by installing ``pre-commit``::
819-
820-
pip install pre-commit
821-
822-
and then running::
823-
824-
pre-commit install
825-
826-
from the root of the pandas repository. Now all of the styling checks will be
827-
run each time you commit changes without your needing to run each one manually.
828-
In addition, using this pre-commit hook will also allow you to more easily
829-
remain up-to-date with our code checks as they change.
830-
831-
Note that if needed, you can skip these checks with ``git commit --no-verify``.
832-
833-
If you don't want to use ``pre-commit`` as part of your workflow, you can still use it
834-
to run its checks by running::
835-
836-
pre-commit run --files <files you have modified>
837-
838-
without having to have done ``pre-commit install`` beforehand.
839-
840-
.. note::
841-
842-
If you have conflicting installations of ``virtualenv``, then you may get an
843-
error - see `here <https://github.com/pypa/virtualenv/issues/1875>`_.
844-
845-
Also, due to a `bug in virtualenv <https://github.com/pypa/virtualenv/issues/1986>`_,
846-
you may run into issues if you're using conda. To solve this, you can downgrade
847-
``virtualenv`` to version ``20.0.33``.
848-
849846
Backwards compatibility
850847
~~~~~~~~~~~~~~~~~~~~~~~
851848

doc/source/user_guide/indexing.rst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,17 @@ above example, ``s.loc[1:6]`` would raise ``KeyError``.
422422
For the rationale behind this behavior, see
423423
:ref:`Endpoints are inclusive <advanced.endpoints_are_inclusive>`.
424424

425+
.. ipython:: python
426+
427+
s = pd.Series(list('abcdef'), index=[0, 3, 2, 5, 4, 2])
428+
s.loc[3:5]
429+
430+
Also, if the index has duplicate labels *and* either the start or the stop label is dupulicated,
431+
an error will be raised. For instance, in the above example, ``s.loc[2:5]`` would raise a ``KeyError``.
432+
433+
For more information about duplicate labels, see
434+
:ref:`Duplicate Labels <duplicates>`.
435+
425436
.. _indexing.integer:
426437

427438
Selection by position
@@ -1594,19 +1605,16 @@ See :ref:`Advanced Indexing <advanced>` for usage of MultiIndexes.
15941605
Set operations on Index objects
15951606
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15961607

1597-
The two main operations are ``union (|)`` and ``intersection (&)``.
1598-
These can be directly called as instance methods or used via overloaded
1599-
operators. Difference is provided via the ``.difference()`` method.
1608+
The two main operations are ``union`` and ``intersection``.
1609+
Difference is provided via the ``.difference()`` method.
16001610

16011611
.. ipython:: python
16021612
16031613
a = pd.Index(['c', 'b', 'a'])
16041614
b = pd.Index(['c', 'e', 'd'])
1605-
a | b
1606-
a & b
16071615
a.difference(b)
16081616
1609-
Also available is the ``symmetric_difference (^)`` operation, which returns elements
1617+
Also available is the ``symmetric_difference`` operation, which returns elements
16101618
that appear in either ``idx1`` or ``idx2``, but not in both. This is
16111619
equivalent to the Index created by ``idx1.difference(idx2).union(idx2.difference(idx1))``,
16121620
with duplicates dropped.
@@ -1616,7 +1624,6 @@ with duplicates dropped.
16161624
idx1 = pd.Index([1, 2, 3, 4])
16171625
idx2 = pd.Index([2, 3, 4, 5])
16181626
idx1.symmetric_difference(idx2)
1619-
idx1 ^ idx2
16201627
16211628
.. note::
16221629

@@ -1631,7 +1638,7 @@ integer values are converted to float
16311638
16321639
idx1 = pd.Index([0, 1, 2])
16331640
idx2 = pd.Index([0.5, 1.5])
1634-
idx1 | idx2
1641+
idx1.union(idx2)
16351642
16361643
.. _indexing.missing:
16371644

doc/source/user_guide/missing_data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ at the new values.
466466
ser = pd.Series(np.sort(np.random.uniform(size=100)))
467467
468468
# interpolate at new_index
469-
new_index = ser.index | pd.Index([49.25, 49.5, 49.75, 50.25, 50.5, 50.75])
469+
new_index = ser.index.union(pd.Index([49.25, 49.5, 49.75, 50.25, 50.5, 50.75]))
470470
interp_s = ser.reindex(new_index).interpolate(method="pchip")
471471
interp_s[49:51]
472472

doc/source/whatsnew/v1.1.5.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17-
-
17+
- Regression in addition of a timedelta-like scalar to a :class:`DatetimeIndex` raising incorrectly (:issue:`37295`)
1818
-
1919

2020
.. ---------------------------------------------------------------------------
@@ -23,7 +23,9 @@ Fixed regressions
2323

2424
Bug fixes
2525
~~~~~~~~~
26-
-
26+
- Bug in metadata propagation for ``groupby`` iterator (:issue:`37343`)
27+
- Bug in indexing on a :class:`Series` with ``CategoricalDtype`` after unpickling (:issue:`37631`)
28+
- Bug in :class:`RollingGroupby` with the resulting :class:`MultiIndex` when grouping by a label that is in the index (:issue:`37641`)
2729
-
2830

2931
.. ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)