Skip to content

Commit 7d37ad8

Browse files
authored
Merge pull request #3 from pandas-dev/master
Sync Fork from Upstream Repo
2 parents e33d165 + 6e9651e commit 7d37ad8

File tree

11 files changed

+113
-112
lines changed

11 files changed

+113
-112
lines changed

doc/source/development/contributing.rst

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ many errors as possible, but it may not correct *all* of them. Thus, it is
635635
recommended that you run ``cpplint`` to double check and make any other style
636636
fixes manually.
637637

638+
.. _contributing.code-formatting:
639+
638640
Python (PEP8 / black)
639641
~~~~~~~~~~~~~~~~~~~~~
640642

@@ -656,27 +658,16 @@ apply ``black`` as you edit files.
656658
You should use a ``black`` version >= 19.10b0 as previous versions are not compatible
657659
with the pandas codebase.
658660

659-
Optionally, you may wish to setup `pre-commit hooks <https://pre-commit.com/>`_
660-
to automatically run ``black`` and ``flake8`` when you make a git commit. This
661-
can be done by installing ``pre-commit``::
662-
663-
pip install pre-commit
664-
665-
and then running::
666-
667-
pre-commit install
668-
669-
from the root of the pandas repository. Now ``black`` and ``flake8`` will be run
670-
each time you commit changes. You can skip these checks with
671-
``git commit --no-verify``.
661+
If you wish to run these checks automatically, we encourage you to use
662+
:ref:`pre-commits <contributing.pre-commit>` instead.
672663

673664
One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this
674665
command will catch any stylistic errors in your changes specifically, but
675666
be beware it may not catch all of them. For example, if you delete the only
676667
usage of an imported function, it is stylistically incorrect to import an
677668
unused function. However, style-checking the diff will not catch this because
678669
the actual import is not part of the diff. Thus, for completeness, you should
679-
run this command, though it will take longer::
670+
run this command, though it may take longer::
680671

681672
git diff upstream/master --name-only -- "*.py" | xargs -r flake8
682673

@@ -694,6 +685,8 @@ behaviour as follows::
694685
This will get all the files being changed by the PR (and ending with ``.py``),
695686
and run ``flake8`` on them, one after the other.
696687

688+
Note that these commands can be run analogously with ``black``.
689+
697690
.. _contributing.import-formatting:
698691

699692
Import formatting
@@ -716,7 +709,6 @@ A summary of our current import sections ( in order ):
716709

717710
Imports are alphabetically sorted within these sections.
718711

719-
720712
As part of :ref:`Continuous Integration <contributing.ci>` checks we run::
721713

722714
isort --recursive --check-only pandas
@@ -740,8 +732,37 @@ to automatically format imports correctly. This will modify your local copy of t
740732

741733
The `--recursive` flag can be passed to sort all files in a directory.
742734

735+
Alternatively, you can run a command similar to what was suggested for ``black`` and ``flake8`` :ref:`right above <contributing.code-formatting>`::
736+
737+
git diff upstream/master --name-only -- "*.py" | xargs -r isort
738+
739+
Where similar caveats apply if you are on OSX or Windows.
740+
743741
You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.
744742

743+
.. _contributing.pre-commit:
744+
745+
Pre-Commit
746+
~~~~~~~~~~
747+
748+
You can run many of these styling checks manually as we have described above. However,
749+
we encourage you to use `pre-commit hooks <https://pre-commit.com/>`_ instead
750+
to automatically run ``black``, ``flake8``, ``isort`` when you make a git commit. This
751+
can be done by installing ``pre-commit``::
752+
753+
pip install pre-commit
754+
755+
and then running::
756+
757+
pre-commit install
758+
759+
from the root of the pandas repository. Now all of the styling checks will be
760+
run each time you commit changes without your needing to run each one manually.
761+
In addition, using this pre-commit hook will also allow you to more easily
762+
remain up-to-date with our code checks as they change.
763+
764+
Note that if needed, you can skip these checks with ``git commit --no-verify``.
765+
745766
Backwards compatibility
746767
~~~~~~~~~~~~~~~~~~~~~~~
747768

doc/source/development/roadmap.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,6 @@ Some specific goals include
129129
* Improve the overall organization of the documentation and specific subsections
130130
of the documentation to make navigation and finding content easier.
131131

132-
Package docstring validation
133-
----------------------------
134-
135-
To improve the quality and consistency of pandas docstrings, we've developed
136-
tooling to check docstrings in a variety of ways.
137-
https://github.com/pandas-dev/pandas/blob/master/scripts/validate_docstrings.py
138-
contains the checks.
139-
140-
Like many other projects, pandas uses the
141-
`numpydoc <https://numpydoc.readthedocs.io/en/latest/>`__ style for writing
142-
docstrings. With the collaboration of the numpydoc maintainers, we'd like to
143-
move the checks to a package other than pandas so that other projects can easily
144-
use them as well.
145-
146132
Performance monitoring
147133
----------------------
148134

pandas/_config/display.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Unopinionated display configuration.
33
"""
4+
45
import locale
56
import sys
67

@@ -11,7 +12,7 @@
1112
_initial_defencoding = None
1213

1314

14-
def detect_console_encoding():
15+
def detect_console_encoding() -> str:
1516
"""
1617
Try to find the most capable encoding supported by the console.
1718
slightly modified from the way IPython handles the same issue.

pandas/_config/localization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
@contextmanager
15-
def set_locale(new_locale, lc_var=locale.LC_ALL):
15+
def set_locale(new_locale, lc_var: int = locale.LC_ALL):
1616
"""
1717
Context manager for temporarily setting a locale.
1818
@@ -44,7 +44,7 @@ def set_locale(new_locale, lc_var=locale.LC_ALL):
4444
locale.setlocale(lc_var, current_locale)
4545

4646

47-
def can_set_locale(lc, lc_var=locale.LC_ALL):
47+
def can_set_locale(lc: str, lc_var: int = locale.LC_ALL) -> bool:
4848
"""
4949
Check to see if we can set a locale, and subsequently get the locale,
5050
without raising an Exception.
@@ -58,7 +58,7 @@ def can_set_locale(lc, lc_var=locale.LC_ALL):
5858
5959
Returns
6060
-------
61-
is_valid : bool
61+
bool
6262
Whether the passed locale can be set
6363
"""
6464

pandas/_testing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def round_trip_pickle(
122122
_path = path
123123
if _path is None:
124124
_path = f"__{rands(10)}__.pickle"
125-
with ensure_clean(_path) as path:
126-
pd.to_pickle(obj, _path)
127-
return pd.read_pickle(_path)
125+
with ensure_clean(_path) as temp_path:
126+
pd.to_pickle(obj, temp_path)
127+
return pd.read_pickle(temp_path)
128128

129129

130130
def round_trip_pathlib(writer, reader, path: Optional[str] = None):

pandas/compat/numpy/function.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,26 @@
3333

3434

3535
class CompatValidator:
36-
def __init__(self, defaults, fname=None, method=None, max_fname_arg_count=None):
36+
def __init__(
37+
self,
38+
defaults,
39+
fname=None,
40+
method: Optional[str] = None,
41+
max_fname_arg_count=None,
42+
):
3743
self.fname = fname
3844
self.method = method
3945
self.defaults = defaults
4046
self.max_fname_arg_count = max_fname_arg_count
4147

42-
def __call__(self, args, kwargs, fname=None, max_fname_arg_count=None, method=None):
48+
def __call__(
49+
self,
50+
args,
51+
kwargs,
52+
fname=None,
53+
max_fname_arg_count=None,
54+
method: Optional[str] = None,
55+
) -> None:
4356
if args or kwargs:
4457
fname = self.fname if fname is None else fname
4558
max_fname_arg_count = (
@@ -300,7 +313,7 @@ def validate_take_with_convert(convert, args, kwargs):
300313
)
301314

302315

303-
def validate_window_func(name, args, kwargs):
316+
def validate_window_func(name, args, kwargs) -> None:
304317
numpy_args = ("axis", "dtype", "out")
305318
msg = (
306319
f"numpy operations are not valid with window objects. "
@@ -315,7 +328,7 @@ def validate_window_func(name, args, kwargs):
315328
raise UnsupportedFunctionCall(msg)
316329

317330

318-
def validate_rolling_func(name, args, kwargs):
331+
def validate_rolling_func(name, args, kwargs) -> None:
319332
numpy_args = ("axis", "dtype", "out")
320333
msg = (
321334
f"numpy operations are not valid with window objects. "
@@ -330,7 +343,7 @@ def validate_rolling_func(name, args, kwargs):
330343
raise UnsupportedFunctionCall(msg)
331344

332345

333-
def validate_expanding_func(name, args, kwargs):
346+
def validate_expanding_func(name, args, kwargs) -> None:
334347
numpy_args = ("axis", "dtype", "out")
335348
msg = (
336349
f"numpy operations are not valid with window objects. "
@@ -345,7 +358,7 @@ def validate_expanding_func(name, args, kwargs):
345358
raise UnsupportedFunctionCall(msg)
346359

347360

348-
def validate_groupby_func(name, args, kwargs, allowed=None):
361+
def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
349362
"""
350363
'args' and 'kwargs' should be empty, except for allowed
351364
kwargs because all of
@@ -359,16 +372,15 @@ def validate_groupby_func(name, args, kwargs, allowed=None):
359372

360373
if len(args) + len(kwargs) > 0:
361374
raise UnsupportedFunctionCall(
362-
f"numpy operations are not valid with "
363-
f"groupby. Use .groupby(...).{name}() "
364-
f"instead"
375+
"numpy operations are not valid with groupby. "
376+
f"Use .groupby(...).{name}() instead"
365377
)
366378

367379

368380
RESAMPLER_NUMPY_OPS = ("min", "max", "sum", "prod", "mean", "std", "var")
369381

370382

371-
def validate_resampler_func(method, args, kwargs):
383+
def validate_resampler_func(method: str, args, kwargs) -> None:
372384
"""
373385
'args' and 'kwargs' should be empty because all of
374386
their necessary parameters are explicitly listed in
@@ -385,7 +397,7 @@ def validate_resampler_func(method, args, kwargs):
385397
raise TypeError("too many arguments passed in")
386398

387399

388-
def validate_minmax_axis(axis):
400+
def validate_minmax_axis(axis: Optional[int]) -> None:
389401
"""
390402
Ensure that the axis argument passed to min, max, argmin, or argmax is
391403
zero or None, as otherwise it will be incorrectly ignored.

pandas/core/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
"pandas.core.index is deprecated and will be removed in a future version. "
2828
"The public classes are available in the top-level namespace.",
2929
FutureWarning,
30+
stacklevel=2,
3031
)

0 commit comments

Comments
 (0)