From dbf17fffd2554ac1fbc6a01bdff98189d15a4a5f Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 07:29:51 +0100 Subject: [PATCH 01/11] update black verison --- .pre-commit-config.yaml | 2 +- doc/source/development/contributing.rst | 2 +- environment.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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 From 4a324606dfacb9352dd054f1c4e434004bf5fcb2 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 07:56:22 +0100 Subject: [PATCH 02/11] upgrade version of 'black' --- asv_bench/benchmarks/arithmetic.py | 2 +- doc/make.py | 2 +- doc/source/conf.py | 2 +- pandas/_vendored/typing_extensions.py | 3 +- pandas/core/aggregation.py | 2 +- pandas/core/algorithms.py | 9 +++--- pandas/core/array_algos/replace.py | 2 +- pandas/core/frame.py | 10 +++---- pandas/core/series.py | 9 +++--- pandas/core/sorting.py | 2 +- pandas/core/util/numba_.py | 2 +- pandas/io/formats/format.py | 4 --- pandas/io/formats/info.py | 29 +++++++++++++++---- pandas/io/formats/latex.py | 6 ++-- pandas/tests/arrays/sparse/test_array.py | 11 +++---- pandas/tests/frame/test_analytics.py | 16 +++++----- pandas/tests/io/formats/test_info.py | 20 +++++++++++++ pandas/tests/io/test_gcs.py | 4 ++- pandas/tests/io/test_parquet.py | 4 ++- .../scalar/timestamp/test_constructors.py | 23 ++++++++------- pandas/tests/series/test_operators.py | 3 +- scripts/tests/test_validate_docstrings.py | 3 +- versioneer.py | 3 +- 23 files changed, 104 insertions(+), 67 deletions(-) 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/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..22674f91cdd58 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 @@ -330,7 +328,8 @@ def __init__( data = SingleBlockManager.from_array(data, index) generic.NDFrame.__init__( - self, data, + 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/info.py b/pandas/io/formats/info.py index 7a53b46a4ac0f..06ca429ff076b 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -340,12 +340,29 @@ def _verbose_repr( if show_counts: count = counts[i] - lines.append( - line_no - + _put_str(col, space) - + _put_str(count_temp.format(count=count), space_count) - + _put_str(dtype, space_dtype) - ) + def _verbose_repr( + self, lines: List[str], ids: "Index", dtypes: "Series", show_counts: bool + ) -> None: + lines.append(f"Series name: {self.data.name}") + + id_space = 2 + + counts = cast("Series", self.data._constructor(self.data.count())) + count_configs = _get_count_configs(counts, id_space, show_counts) + + space_dtype, header, len_dtype = _get_header_and_spaces( + dtypes, count_configs.space_count, count_configs.count_header + ) + + lines.append(header) + lines.append( + _put_str("-" * count_configs.len_count, count_configs.space_count) + + _put_str("-" * len_dtype, space_dtype) + ) + + _display_counts_and_dtypes( + lines, ids, dtypes, show_counts, count_configs, space_dtype + ) def _non_verbose_repr(self, lines: List[str], ids: "Index") -> None: lines.append(ids._summary(name="Columns")) diff --git a/pandas/io/formats/latex.py b/pandas/io/formats/latex.py index eb35fff3a4f8e..a70cd771e76c2 100644 --- a/pandas/io/formats/latex.py +++ b/pandas/io/formats/latex.py @@ -41,9 +41,9 @@ 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: """Get string representation of the row.""" diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index ece9367cea7fe..03bf31703758d 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 @@ -696,14 +694,17 @@ def test_getslice_tuple(self): res = sparse[ 4:, ] # noqa: E231 - exp = SparseArray(dense[4:,]) # noqa: E231 + exp = SparseArray(np.array([0, 5, np.nan, np.nan, 0])) 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 + exp = SparseArray( + np.array([0, 5, np.nan, np.nan, 0]), + fill_value=0, + ) # noqa: E231 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/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 7000daeb9b575..7df981865af1d 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -371,6 +371,26 @@ def test_info_memory_usage_qualified(): df.info(buf=buf) assert "+" in buf.getvalue() + buf = StringIO() + s = Series(1, index=[1, 2, 3]) + s.info(buf=buf) + assert "+" not in buf.getvalue() + + buf = StringIO() + s = Series(1, index=list("ABC")) + s.info(buf=buf) + assert "+" in buf.getvalue() + + buf = StringIO() + s = Series(1, index=MultiIndex.from_product([range(3), range(3)])) + s.info(buf=buf) + assert "+" not in buf.getvalue() + + buf = StringIO() + s = Series(1, index=MultiIndex.from_product([range(3), ["foo", "bar"]])) + s.info(buf=buf) + assert "+" in buf.getvalue() + def test_info_memory_usage_bug_on_multiindex(): # GH 14308 diff --git a/pandas/tests/io/test_gcs.py b/pandas/tests/io/test_gcs.py index 18b5743a3375a..60e2116a97189 100644 --- a/pandas/tests/io/test_gcs.py +++ b/pandas/tests/io/test_gcs.py @@ -109,7 +109,9 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding) compression["method"] = "infer" path_gcs += f".{compression_only}" df.to_csv( - path_gcs, compression=compression, encoding=encoding, + 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) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 35a400cba8671..64e424cff473d 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -572,7 +572,9 @@ 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..8ae36e38b58ca 100644 --- a/pandas/tests/series/test_operators.py +++ b/pandas/tests/series/test_operators.py @@ -555,7 +555,8 @@ def test_unary_minus_nullable_int( tm.assert_series_equal(result, expected) @pytest.mark.parametrize( - "source", [[1, 2, 3], [1, 2, None], [-1, 0, 1]], + "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 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..a07e04db43517 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1073,7 +1073,8 @@ 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) :] From 30f2a593cff9ffc7eb9fa178fc932ae5940975f9 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:00:55 +0100 Subject: [PATCH 03/11] rebase error --- pandas/io/formats/info.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 06ca429ff076b..7a53b46a4ac0f 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -340,29 +340,12 @@ def _verbose_repr( if show_counts: count = counts[i] - def _verbose_repr( - self, lines: List[str], ids: "Index", dtypes: "Series", show_counts: bool - ) -> None: - lines.append(f"Series name: {self.data.name}") - - id_space = 2 - - counts = cast("Series", self.data._constructor(self.data.count())) - count_configs = _get_count_configs(counts, id_space, show_counts) - - space_dtype, header, len_dtype = _get_header_and_spaces( - dtypes, count_configs.space_count, count_configs.count_header - ) - - lines.append(header) - lines.append( - _put_str("-" * count_configs.len_count, count_configs.space_count) - + _put_str("-" * len_dtype, space_dtype) - ) - - _display_counts_and_dtypes( - lines, ids, dtypes, show_counts, count_configs, space_dtype - ) + lines.append( + line_no + + _put_str(col, space) + + _put_str(count_temp.format(count=count), space_count) + + _put_str(dtype, space_dtype) + ) def _non_verbose_repr(self, lines: List[str], ids: "Index") -> None: lines.append(ids._summary(name="Columns")) From 6259dedb040984adb85430aa0b708a1e06faf39a Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:02:03 +0100 Subject: [PATCH 04/11] rebase error continued --- pandas/tests/io/formats/test_info.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 7df981865af1d..7000daeb9b575 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -371,26 +371,6 @@ def test_info_memory_usage_qualified(): df.info(buf=buf) assert "+" in buf.getvalue() - buf = StringIO() - s = Series(1, index=[1, 2, 3]) - s.info(buf=buf) - assert "+" not in buf.getvalue() - - buf = StringIO() - s = Series(1, index=list("ABC")) - s.info(buf=buf) - assert "+" in buf.getvalue() - - buf = StringIO() - s = Series(1, index=MultiIndex.from_product([range(3), range(3)])) - s.info(buf=buf) - assert "+" not in buf.getvalue() - - buf = StringIO() - s = Series(1, index=MultiIndex.from_product([range(3), ["foo", "bar"]])) - s.info(buf=buf) - assert "+" in buf.getvalue() - def test_info_memory_usage_bug_on_multiindex(): # GH 14308 From ebbef30ffec4a26efd29f0ae2d5579841104d772 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:03:08 +0100 Subject: [PATCH 05/11] :art: --- pandas/core/series.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 22674f91cdd58..0984e86a23592 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -327,10 +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) From 4c67eb77670176fbe79754e23f701d60165dd041 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:05:42 +0100 Subject: [PATCH 06/11] pandas/tests/arrays/sparse/test_array.py --- pandas/tests/arrays/sparse/test_array.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 03bf31703758d..c847e7d4b0af5 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -193,7 +193,10 @@ 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 @@ -694,7 +697,11 @@ def test_getslice_tuple(self): res = sparse[ 4:, ] # noqa: E231 - exp = SparseArray(np.array([0, 5, np.nan, np.nan, 0])) + exp = SparseArray( + dense[ + 4:, + ] + ) # noqa: E231 tm.assert_sp_array_equal(res, exp) sparse = SparseArray(dense, fill_value=0) @@ -702,7 +709,9 @@ def test_getslice_tuple(self): 4:, ] # noqa: E231 exp = SparseArray( - np.array([0, 5, np.nan, np.nan, 0]), + dense[ + 4:, + ], fill_value=0, ) # noqa: E231 tm.assert_sp_array_equal(res, exp) From 10eefa574919fbe758ead787d77bae4943b38bc2 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:07:31 +0100 Subject: [PATCH 07/11] trailing commas --- pandas/tests/io/test_gcs.py | 6 +----- pandas/tests/io/test_parquet.py | 4 +--- pandas/tests/series/test_operators.py | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pandas/tests/io/test_gcs.py b/pandas/tests/io/test_gcs.py index 60e2116a97189..9d179d983ceeb 100644 --- a/pandas/tests/io/test_gcs.py +++ b/pandas/tests/io/test_gcs.py @@ -108,11 +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 64e424cff473d..a5033c51bce81 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -572,9 +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/series/test_operators.py b/pandas/tests/series/test_operators.py index 8ae36e38b58ca..a796023c75b78 100644 --- a/pandas/tests/series/test_operators.py +++ b/pandas/tests/series/test_operators.py @@ -554,10 +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) From 518f28bb2c0228fbe487e0ca7204f7b387241ce7 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:08:47 +0100 Subject: [PATCH 08/11] trailing commas --- pandas/tests/arrays/sparse/test_array.py | 5 +---- versioneer.py | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index c847e7d4b0af5..b4e4647c9bf35 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -193,10 +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 diff --git a/versioneer.py b/versioneer.py index a07e04db43517..171156c2c5315 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1073,8 +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) :] From c4244049cfba5d975465fc0147ee7609ccac5b29 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:12:31 +0100 Subject: [PATCH 09/11] generate_pip_deps_from_conda --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b73d66ad46726f606cce86d8570d0d94fde18470 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 20 Sep 2020 08:37:03 +0100 Subject: [PATCH 10/11] remove trailing commas --- pandas/tests/arrays/sparse/test_array.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index b4e4647c9bf35..5d9bae65bd6ca 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -691,26 +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[4:] + 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[4:] + exp = SparseArray(dense[4:], fill_value=0) tm.assert_sp_array_equal(res, exp) msg = "too many indices for array" From 5fd78c06d2685633c84dabd73c3660e8f382f6f7 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Mon, 21 Sep 2020 12:15:05 +0100 Subject: [PATCH 11/11] fix typing, use slice --- pandas/io/formats/latex.py | 4 ++-- pandas/tests/arrays/sparse/test_array.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/io/formats/latex.py b/pandas/io/formats/latex.py index a70cd771e76c2..170df193bef00 100644 --- a/pandas/io/formats/latex.py +++ b/pandas/io/formats/latex.py @@ -42,8 +42,8 @@ def __init__( self.clinebuf: List[List[int]] = [] self.strcols = self._get_strcols() self.strrows: List[List[str]] = list( - zip(*self.strcols) - ) # type: ignore[arg-type] + zip(*self.strcols) # type: ignore[arg-type] + ) def get_strrow(self, row_num: int) -> str: """Get string representation of the row.""" diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 5d9bae65bd6ca..f18117cfd3d1f 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -691,12 +691,12 @@ 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:] + 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:] + res = sparse[(slice(4, None),)] exp = SparseArray(dense[4:], fill_value=0) tm.assert_sp_array_equal(res, exp)