diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 309e22e71a523..dd5323960ed20 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/python/black - rev: 19.10b0 + rev: 20.8b1 hooks: - id: black language_version: python3 diff --git a/asv_bench/benchmarks/arithmetic.py b/asv_bench/benchmarks/arithmetic.py index 3ef6ab6209ea7..5a3febdcf75e7 100644 --- a/asv_bench/benchmarks/arithmetic.py +++ b/asv_bench/benchmarks/arithmetic.py @@ -125,7 +125,7 @@ def setup(self, op): arr1 = np.random.randn(n_rows, int(n_cols / 2)).astype("f8") arr2 = np.random.randn(n_rows, int(n_cols / 2)).astype("f4") df = pd.concat( - [pd.DataFrame(arr1), pd.DataFrame(arr2)], axis=1, ignore_index=True, + [pd.DataFrame(arr1), pd.DataFrame(arr2)], axis=1, ignore_index=True ) # should already be the case, but just to be sure df._consolidate_inplace() diff --git a/doc/make.py b/doc/make.py index 94fbfa9382d81..40ce9ea3bbcd2 100755 --- a/doc/make.py +++ b/doc/make.py @@ -286,7 +286,7 @@ def main(): joined = ",".join(cmds) argparser = argparse.ArgumentParser( - description="pandas documentation builder", epilog=f"Commands: {joined}", + description="pandas documentation builder", epilog=f"Commands: {joined}" ) joined = ", ".join(cmds) diff --git a/doc/source/conf.py b/doc/source/conf.py index ee0d4ca3f2a24..04540f7e6ec95 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -308,7 +308,7 @@ for method in methods: # ... and each of its public methods - moved_api_pages.append((f"{old}.{method}", f"{new}.{method}",)) + moved_api_pages.append((f"{old}.{method}", f"{new}.{method}")) if pattern is None: html_additional_pages = { diff --git a/doc/source/development/contributing.rst b/doc/source/development/contributing.rst index e5c6f77eea3ef..8558774955a40 100644 --- a/doc/source/development/contributing.rst +++ b/doc/source/development/contributing.rst @@ -720,7 +720,7 @@ submitting code to run the check yourself:: to auto-format your code. Additionally, many editors have plugins that will apply ``black`` as you edit files. -You should use a ``black`` version >= 19.10b0 as previous versions are not compatible +You should use a ``black`` version 20.8b1 as previous versions are not compatible with the pandas codebase. If you wish to run these checks automatically, we encourage you to use diff --git a/environment.yml b/environment.yml index 36bbd3d307159..ffd319b006ff2 100644 --- a/environment.yml +++ b/environment.yml @@ -15,7 +15,7 @@ dependencies: - cython>=0.29.21 # code checks - - black=19.10b0 + - black=20.8b1 - cpplint - flake8<3.8.0 # temporary pin, GH#34150 - flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions diff --git a/pandas/_vendored/typing_extensions.py b/pandas/_vendored/typing_extensions.py index 129d8998faccc..6efbbe9302952 100644 --- a/pandas/_vendored/typing_extensions.py +++ b/pandas/_vendored/typing_extensions.py @@ -2116,8 +2116,7 @@ def __init_subclass__(cls, *args, **kwargs): raise TypeError(f"Cannot subclass {cls.__module__}.Annotated") def _strip_annotations(t): - """Strips the annotations from a given type. - """ + """Strips the annotations from a given type.""" if isinstance(t, _AnnotatedAlias): return _strip_annotations(t.__origin__) if isinstance(t, typing._GenericAlias): diff --git a/pandas/core/aggregation.py b/pandas/core/aggregation.py index c123156495924..541c617f7f618 100644 --- a/pandas/core/aggregation.py +++ b/pandas/core/aggregation.py @@ -387,7 +387,7 @@ def validate_func_kwargs( def transform( - obj: FrameOrSeries, func: AggFuncType, axis: Axis, *args, **kwargs, + obj: FrameOrSeries, func: AggFuncType, axis: Axis, *args, **kwargs ) -> FrameOrSeries: """ Transform a DataFrame or Series diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 50d1810fee30d..ccccdc4409694 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1023,11 +1023,10 @@ def checked_add_with_arr(arr, b, arr_mask=None, b_mask=None): to_raise = ((np.iinfo(np.int64).max - b2 < arr) & not_nan).any() else: to_raise = ( - ((np.iinfo(np.int64).max - b2[mask1] < arr[mask1]) & not_nan[mask1]).any() - or ( - (np.iinfo(np.int64).min - b2[mask2] > arr[mask2]) & not_nan[mask2] - ).any() - ) + (np.iinfo(np.int64).max - b2[mask1] < arr[mask1]) & not_nan[mask1] + ).any() or ( + (np.iinfo(np.int64).min - b2[mask2] > arr[mask2]) & not_nan[mask2] + ).any() if to_raise: raise OverflowError("Overflow in int64 addition") diff --git a/pandas/core/array_algos/replace.py b/pandas/core/array_algos/replace.py index 09f9aefd64096..9eaa265adab2b 100644 --- a/pandas/core/array_algos/replace.py +++ b/pandas/core/array_algos/replace.py @@ -17,7 +17,7 @@ def compare_or_regex_search( - a: ArrayLike, b: Union[Scalar, Pattern], regex: bool, mask: ArrayLike, + a: ArrayLike, b: Union[Scalar, Pattern], regex: bool, mask: ArrayLike ) -> Union[ArrayLike, bool]: """ Compare two array_like inputs of the same shape or two scalar values diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 36dfe43bfd708..47b127b300681 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -449,9 +449,7 @@ def __init__( if isinstance(data, BlockManager): if index is None and columns is None and dtype is None and copy is False: # GH#33357 fastpath - NDFrame.__init__( - self, data, - ) + NDFrame.__init__(self, data) return mgr = self._init_mgr( @@ -5747,7 +5745,7 @@ def nsmallest(self, n, columns, keep="first") -> DataFrame: population GDP alpha-2 Tuvalu 11300 38 TV Anguilla 11300 311 AI - Iceland 337000 17036 IS + Iceland 337000 17036 IS When using ``keep='last'``, ties are resolved in reverse order: @@ -7142,7 +7140,7 @@ def unstack(self, level=-1, fill_value=None): return unstack(self, level, fill_value) - @Appender(_shared_docs["melt"] % dict(caller="df.melt(", other="melt",)) + @Appender(_shared_docs["melt"] % dict(caller="df.melt(", other="melt")) def melt( self, id_vars=None, @@ -8624,7 +8622,7 @@ def blk_func(values): # After possibly _get_data and transposing, we are now in the # simple case where we can use BlockManager.reduce res = df._mgr.reduce(blk_func) - out = df._constructor(res,).iloc[0].rename(None) + out = df._constructor(res).iloc[0].rename(None) if out_dtype is not None: out = out.astype(out_dtype) if axis == 0 and is_object_dtype(out.dtype): diff --git a/pandas/core/series.py b/pandas/core/series.py index 48fae9a0a91cd..0984e86a23592 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -198,7 +198,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): # Constructors def __init__( - self, data=None, index=None, dtype=None, name=None, copy=False, fastpath=False, + self, data=None, index=None, dtype=None, name=None, copy=False, fastpath=False ): if ( @@ -208,9 +208,7 @@ def __init__( and copy is False ): # GH#33357 called with just the SingleBlockManager - NDFrame.__init__( - self, data, - ) + NDFrame.__init__(self, data) self.name = name return @@ -329,9 +327,7 @@ def __init__( data = SingleBlockManager.from_array(data, index) - generic.NDFrame.__init__( - self, data, - ) + generic.NDFrame.__init__(self, data) self.name = name self._set_axis(0, index, fastpath=True) diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index ec62192464665..1fec2bbbf5fdc 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -72,7 +72,7 @@ def get_indexer_indexer( ) elif isinstance(target, ABCMultiIndex): indexer = lexsort_indexer( - target._get_codes_for_sorting(), orders=ascending, na_position=na_position, + target._get_codes_for_sorting(), orders=ascending, na_position=na_position ) else: # Check monotonic-ness before sort an index (GH 11080) diff --git a/pandas/core/util/numba_.py b/pandas/core/util/numba_.py index f06dd10d0e497..1dd005c1602a5 100644 --- a/pandas/core/util/numba_.py +++ b/pandas/core/util/numba_.py @@ -25,7 +25,7 @@ def set_use_numba(enable: bool = False) -> None: def get_jit_arguments( - engine_kwargs: Optional[Dict[str, bool]] = None, kwargs: Optional[Dict] = None, + engine_kwargs: Optional[Dict[str, bool]] = None, kwargs: Optional[Dict] = None ) -> Tuple[bool, bool, bool]: """ Return arguments to pass to numba.JIT, falling back on pandas default JIT settings. diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 7eb31daa894c9..99992d0218a68 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1382,10 +1382,6 @@ def _format(x): class FloatArrayFormatter(GenericArrayFormatter): - """ - - """ - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/pandas/io/formats/latex.py b/pandas/io/formats/latex.py index eb35fff3a4f8e..170df193bef00 100644 --- a/pandas/io/formats/latex.py +++ b/pandas/io/formats/latex.py @@ -41,8 +41,8 @@ def __init__( self.multirow = multirow self.clinebuf: List[List[int]] = [] self.strcols = self._get_strcols() - self.strrows: List[List[str]] = ( - list(zip(*self.strcols)) # type: ignore[arg-type] + self.strrows: List[List[str]] = list( + zip(*self.strcols) # type: ignore[arg-type] ) def get_strrow(self, row_num: int) -> str: diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index ece9367cea7fe..f18117cfd3d1f 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -193,9 +193,7 @@ def test_constructor_inferred_fill_value(self, data, fill_value): assert result == fill_value @pytest.mark.parametrize("format", ["coo", "csc", "csr"]) - @pytest.mark.parametrize( - "size", [0, 10], - ) + @pytest.mark.parametrize("size", [0, 10]) @td.skip_if_no_scipy def test_from_spmatrix(self, size, format): import scipy.sparse @@ -693,17 +691,13 @@ def test_getslice_tuple(self): dense = np.array([np.nan, 0, 3, 4, 0, 5, np.nan, np.nan, 0]) sparse = SparseArray(dense) - res = sparse[ - 4:, - ] # noqa: E231 - exp = SparseArray(dense[4:,]) # noqa: E231 + res = sparse[(slice(4, None),)] + exp = SparseArray(dense[4:]) tm.assert_sp_array_equal(res, exp) sparse = SparseArray(dense, fill_value=0) - res = sparse[ - 4:, - ] # noqa: E231 - exp = SparseArray(dense[4:,], fill_value=0) # noqa: E231 + res = sparse[(slice(4, None),)] + exp = SparseArray(dense[4:], fill_value=0) tm.assert_sp_array_equal(res, exp) msg = "too many indices for array" diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index f21b1d3dfe487..4324b03ed13d6 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1060,14 +1060,14 @@ def test_any_all_bool_only(self): (np.any, {"A": pd.Series([0.0, 1.0], dtype="float")}, True), (np.all, {"A": pd.Series([0, 1], dtype=int)}, False), (np.any, {"A": pd.Series([0, 1], dtype=int)}, True), - pytest.param(np.all, {"A": pd.Series([0, 1], dtype="M8[ns]")}, False,), - pytest.param(np.any, {"A": pd.Series([0, 1], dtype="M8[ns]")}, True,), - pytest.param(np.all, {"A": pd.Series([1, 2], dtype="M8[ns]")}, True,), - pytest.param(np.any, {"A": pd.Series([1, 2], dtype="M8[ns]")}, True,), - pytest.param(np.all, {"A": pd.Series([0, 1], dtype="m8[ns]")}, False,), - pytest.param(np.any, {"A": pd.Series([0, 1], dtype="m8[ns]")}, True,), - pytest.param(np.all, {"A": pd.Series([1, 2], dtype="m8[ns]")}, True,), - pytest.param(np.any, {"A": pd.Series([1, 2], dtype="m8[ns]")}, True,), + pytest.param(np.all, {"A": pd.Series([0, 1], dtype="M8[ns]")}, False), + pytest.param(np.any, {"A": pd.Series([0, 1], dtype="M8[ns]")}, True), + pytest.param(np.all, {"A": pd.Series([1, 2], dtype="M8[ns]")}, True), + pytest.param(np.any, {"A": pd.Series([1, 2], dtype="M8[ns]")}, True), + pytest.param(np.all, {"A": pd.Series([0, 1], dtype="m8[ns]")}, False), + pytest.param(np.any, {"A": pd.Series([0, 1], dtype="m8[ns]")}, True), + pytest.param(np.all, {"A": pd.Series([1, 2], dtype="m8[ns]")}, True), + pytest.param(np.any, {"A": pd.Series([1, 2], dtype="m8[ns]")}, True), (np.all, {"A": pd.Series([0, 1], dtype="category")}, False), (np.any, {"A": pd.Series([0, 1], dtype="category")}, True), (np.all, {"A": pd.Series([1, 2], dtype="category")}, True), diff --git a/pandas/tests/io/test_gcs.py b/pandas/tests/io/test_gcs.py index 18b5743a3375a..9d179d983ceeb 100644 --- a/pandas/tests/io/test_gcs.py +++ b/pandas/tests/io/test_gcs.py @@ -108,9 +108,7 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding) compression_only = "gz" compression["method"] = "infer" path_gcs += f".{compression_only}" - df.to_csv( - path_gcs, compression=compression, encoding=encoding, - ) + df.to_csv(path_gcs, compression=compression, encoding=encoding) assert gcs_buffer.getvalue() == buffer.getvalue() read_df = read_csv(path_gcs, index_col=0, compression="infer", encoding=encoding) tm.assert_frame_equal(df, read_df) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 35a400cba8671..a5033c51bce81 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -572,7 +572,7 @@ def test_s3_roundtrip(self, df_compat, s3_resource, pa, s3so): pytest.param( ["A"], marks=pytest.mark.xfail( - PY38, reason="Getting back empty DataFrame", raises=AssertionError, + PY38, reason="Getting back empty DataFrame", raises=AssertionError ), ), [], diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 316a299ba1cbb..d1c3ad508d877 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -259,17 +259,20 @@ def test_constructor_keyword(self): Timestamp("20151112") ) - assert repr( - Timestamp( - year=2015, - month=11, - day=12, - hour=1, - minute=2, - second=3, - microsecond=999999, + assert ( + repr( + Timestamp( + year=2015, + month=11, + day=12, + hour=1, + minute=2, + second=3, + microsecond=999999, + ) ) - ) == repr(Timestamp("2015-11-12 01:02:03.999999")) + == repr(Timestamp("2015-11-12 01:02:03.999999")) + ) def test_constructor_fromordinal(self): base = datetime(2000, 1, 1) diff --git a/pandas/tests/series/test_operators.py b/pandas/tests/series/test_operators.py index aee947e738525..a796023c75b78 100644 --- a/pandas/tests/series/test_operators.py +++ b/pandas/tests/series/test_operators.py @@ -554,9 +554,7 @@ def test_unary_minus_nullable_int( expected = pd.Series(target, dtype=dtype) tm.assert_series_equal(result, expected) - @pytest.mark.parametrize( - "source", [[1, 2, 3], [1, 2, None], [-1, 0, 1]], - ) + @pytest.mark.parametrize("source", [[1, 2, 3], [1, 2, None], [-1, 0, 1]]) def test_unary_plus_nullable_int(self, any_signed_nullable_int_dtype, source): dtype = any_signed_nullable_int_dtype expected = pd.Series(source, dtype=dtype) diff --git a/requirements-dev.txt b/requirements-dev.txt index fb647c10f72bc..4f93ce9017f91 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ python-dateutil>=2.7.3 pytz asv cython>=0.29.21 -black==19.10b0 +black==20.8b1 cpplint flake8<3.8.0 flake8-comprehensions>=3.1.0 diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index b11de0c4ad860..74819db7b878c 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -6,8 +6,7 @@ class BadDocstrings: - """Everything here has a bad docstring - """ + """Everything here has a bad docstring""" def private_classes(self): """ diff --git a/versioneer.py b/versioneer.py index 65c9523ba5573..171156c2c5315 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1073,7 +1073,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): fmt = "tag '%s' doesn't start with prefix '%s'" print(fmt % (full_tag, tag_prefix)) pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format( - full_tag, tag_prefix, + full_tag, tag_prefix ) return pieces pieces["closest-tag"] = full_tag[len(tag_prefix) :]