Description
Code Sampl
black pandas
Problem description
Currently if using virtualenv
instead of conda, in Python 3.7.4
and pip pip 19.3.1
the requirements automatically install black==19.10b0
which differs from the conda workflow which install the black==19.3b0
version.
Expected Output
reformatted /Users/sofianemahiou/Work/pandas/pandas/io/common.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/groupby/grouper.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/algorithms.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/indexing.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/internals/managers.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/indexes/base.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/arrays/sparse/test_array.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/io/parsers.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/io/stata.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/frame.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/dtypes/test_inference.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/io/parser/test_index_col.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/indexing/test_callable.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/indexes/period/test_construction.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/core/generic.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/test_nanops.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/reductions/test_reductions.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/frame/test_constructors.py
reformatted /Users/sofianemahiou/Work/pandas/pandas/tests/test_algos.py
Git diff
diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py
index c70e62377..cc6c23929 100644
--- a/pandas/core/algorithms.py
+++ b/pandas/core/algorithms.py
@@ -1155,7 +1155,7 @@ class SelectNSeries(SelectN):
n = min(n, narr)
kth_val = algos.kth_smallest(arr.copy(), n - 1)
- ns, = np.nonzero(arr <= kth_val)
+ (ns,) = np.nonzero(arr <= kth_val)
inds = ns[arr[ns].argsort(kind="mergesort")]
if self.keep != "all":
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
index 40efc4c65..7d8cc0b73 100644
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -4829,7 +4829,7 @@ class DataFrame(NDFrame):
duplicated = self.duplicated(subset, keep=keep)
if inplace:
- inds, = (-duplicated)._ndarray_values.nonzero()
+ (inds,) = (-duplicated)._ndarray_values.nonzero()
new_data = self._data.take(inds)
self._update_inplace(new_data)
else:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
index f88c26c7b..fa43206b8 100644
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -3613,7 +3613,7 @@ class NDFrame(PandasObject, SelectionMixin):
if isinstance(loc, np.ndarray):
if loc.dtype == np.bool_:
- inds, = loc.nonzero()
+ (inds,) = loc.nonzero()
return self.take(inds, axis=axis)
else:
return self.take(loc, axis=axis)
diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py
index d7eaaca5a..d6beefbf3 100644
--- a/pandas/core/groupby/grouper.py
+++ b/pandas/core/groupby/grouper.py
@@ -284,7 +284,11 @@ class Grouping:
if self.name is None:
self.name = index.names[level]
- self.grouper, self._labels, self._group_index = index._get_grouper_for_level( # noqa: E501
+ (
+ self.grouper,
+ self._labels,
+ self._group_index,
+ ) = index._get_grouper_for_level( # noqa: E501
self.grouper, level
)
diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py
index 187c7e2f3..954607a0d 100644
--- a/pandas/core/indexes/base.py
+++ b/pandas/core/indexes/base.py
@@ -1873,7 +1873,7 @@ class Index(IndexOpsMixin, PandasObject):
@cache_readonly
def _nan_idxs(self):
if self._can_hold_na:
- w, = self._isnan.nonzero()
+ (w,) = self._isnan.nonzero()
return w
else:
return np.array([], dtype=np.int64)
diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py
index 44c786f00..1315e9d5b 100755
--- a/pandas/core/indexing.py
+++ b/pandas/core/indexing.py
@@ -320,7 +320,7 @@ class _NDFrameIndexer(_NDFrameIndexerBase):
# if there is only one block/type, still have to take split path
# unless the block is one-dimensional or it can hold the value
if not take_split_path and self.obj._data.blocks:
- blk, = self.obj._data.blocks
+ (blk,) = self.obj._data.blocks
if 1 < blk.ndim: # in case of dict, keys are indices
val = list(value.values()) if isinstance(value, dict) else value
take_split_path = not blk._can_hold_element(val)
@@ -1120,7 +1120,7 @@ class _NDFrameIndexer(_NDFrameIndexerBase):
if com.is_bool_indexer(key):
# A boolean indexer
key = check_bool_indexer(labels, key)
- inds, = key.nonzero()
+ (inds,) = key.nonzero()
return self.obj.take(inds, axis=axis)
else:
# A collection of keys
@@ -1264,7 +1264,7 @@ class _NDFrameIndexer(_NDFrameIndexerBase):
if com.is_bool_indexer(obj):
obj = check_bool_indexer(labels, obj)
- inds, = obj.nonzero()
+ (inds,) = obj.nonzero()
return inds
else:
# When setting, missing keys are not allowed, even with .loc:
diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py
index c47aaf7c7..db782b455 100644
--- a/pandas/core/internals/managers.py
+++ b/pandas/core/internals/managers.py
@@ -1868,7 +1868,7 @@ def _stack_arrays(tuples, dtype):
def _interleaved_dtype(
- blocks: List[Block]
+ blocks: List[Block],
) -> Optional[Union[np.dtype, ExtensionDtype]]:
"""Find the common dtype for `blocks`.
diff --git a/pandas/io/common.py b/pandas/io/common.py
index 0bef14e49..e08fd37e6 100644
--- a/pandas/io/common.py
+++ b/pandas/io/common.py
@@ -109,7 +109,7 @@ def _is_url(url) -> bool:
def _expand_user(
- filepath_or_buffer: FilePathOrBuffer[AnyStr]
+ filepath_or_buffer: FilePathOrBuffer[AnyStr],
) -> FilePathOrBuffer[AnyStr]:
"""Return the argument with an initial component of ~ or ~user
replaced by that user's home directory.
@@ -139,7 +139,7 @@ def _validate_header_arg(header) -> None:
def _stringify_path(
- filepath_or_buffer: FilePathOrBuffer[AnyStr]
+ filepath_or_buffer: FilePathOrBuffer[AnyStr],
) -> FilePathOrBuffer[AnyStr]:
"""Attempt to convert a path-like object to a string.
diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py
index 058d65b94..4ff988acf 100755
--- a/pandas/io/parsers.py
+++ b/pandas/io/parsers.py
@@ -1918,7 +1918,12 @@ class CParserWrapper(ParserBase):
else:
if len(self._reader.header) > 1:
# we have a multi index in the columns
- self.names, self.index_names, self.col_names, passed_names = self._extract_multi_indexer_columns( # noqa: E501
+ (
+ self.names,
+ self.index_names,
+ self.col_names,
+ passed_names,
+ ) = self._extract_multi_indexer_columns( # noqa: E501
self._reader.header, self.index_names, self.col_names, passed_names
)
else:
@@ -2307,7 +2312,12 @@ class PythonParser(ParserBase):
# The original set is stored in self.original_columns.
if len(self.columns) > 1:
# we are processing a multi index column
- self.columns, self.index_names, self.col_names, _ = self._extract_multi_indexer_columns( # noqa: E501
+ (
+ self.columns,
+ self.index_names,
+ self.col_names,
+ _,
+ ) = self._extract_multi_indexer_columns( # noqa: E501
self.columns, self.index_names, self.col_names
)
# Update list of original names to include all indices.
diff --git a/pandas/io/stata.py b/pandas/io/stata.py
index 07475f224..8e5fa48d4 100644
--- a/pandas/io/stata.py
+++ b/pandas/io/stata.py
@@ -614,7 +614,7 @@ def _cast_to_stata_types(data):
data[col] = data[col].astype(np.int32)
else:
data[col] = data[col].astype(np.float64)
- if data[col].max() >= 2 ** 53 or data[col].min() <= -2 ** 53:
+ if data[col].max() >= 2 ** 53 or data[col].min() <= -(2 ** 53):
ws = precision_loss_doc % ("int64", "float64")
elif dtype in (np.float32, np.float64):
value = data[col].max()
diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py
index f9bb4981d..755cbfb71 100644
--- a/pandas/tests/arrays/sparse/test_array.py
+++ b/pandas/tests/arrays/sparse/test_array.py
@@ -658,12 +658,16 @@ class TestSparseArray:
dense = np.array([np.nan, 0, 3, 4, 0, 5, np.nan, np.nan, 0])
sparse = SparseArray(dense)
- res = sparse[4:,] # noqa: E231
+ res = sparse[
+ 4:,
+ ] # noqa: E231
exp = SparseArray(dense[4:,]) # noqa: E231
tm.assert_sp_array_equal(res, exp)
sparse = SparseArray(dense, fill_value=0)
- res = sparse[4:,] # noqa: E231
+ res = sparse[
+ 4:,
+ ] # noqa: E231
exp = SparseArray(dense[4:,], fill_value=0) # noqa: E231
tm.assert_sp_array_equal(res, exp)
@@ -823,11 +827,11 @@ class TestSparseArray:
# Tests regression #21172.
sa = pd.SparseArray([float("nan"), float("nan"), 1, 0, 0, 2, 0, 0, 0, 3, 0, 0])
expected = np.array([2, 5, 9], dtype=np.int32)
- result, = sa.nonzero()
+ (result,) = sa.nonzero()
tm.assert_numpy_array_equal(expected, result)
sa = pd.SparseArray([0, 0, 1, 0, 0, 2, 0, 0, 0, 3, 0, 0])
- result, = sa.nonzero()
+ (result,) = sa.nonzero()
tm.assert_numpy_array_equal(expected, result)
diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py
index 62fb118f7..7d5b1891c 100644
--- a/pandas/tests/dtypes/test_inference.py
+++ b/pandas/tests/dtypes/test_inference.py
@@ -505,7 +505,7 @@ class TestInference:
result = lib.maybe_convert_numeric(case, set(), coerce_numeric=coerce)
tm.assert_almost_equal(result, expected)
- @pytest.mark.parametrize("value", [-2 ** 63 - 1, 2 ** 64])
+ @pytest.mark.parametrize("value", [-(2 ** 63) - 1, 2 ** 64])
def test_convert_int_overflow(self, value):
# see gh-18584
arr = np.array([value], dtype=object)
diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py
index aa00cf234..f193f97ae 100644
--- a/pandas/tests/frame/test_constructors.py
+++ b/pandas/tests/frame/test_constructors.py
@@ -245,9 +245,9 @@ class TestDataFrameConstructors:
np.array([2 ** 64], dtype=object),
np.array([2 ** 65]),
[2 ** 64 + 1],
- np.array([-2 ** 63 - 4], dtype=object),
- np.array([-2 ** 64 - 1]),
- [-2 ** 65 - 2],
+ np.array([-(2 ** 63) - 4], dtype=object),
+ np.array([-(2 ** 64) - 1]),
+ [-(2 ** 65) - 2],
],
)
def test_constructor_int_overflow(self, values):
diff --git a/pandas/tests/indexes/period/test_construction.py b/pandas/tests/indexes/period/test_construction.py
index 8c75fbbae..1973cb7f4 100644
--- a/pandas/tests/indexes/period/test_construction.py
+++ b/pandas/tests/indexes/period/test_construction.py
@@ -434,7 +434,7 @@ class TestPeriodIndex:
with tm.assert_produces_warning(FutureWarning) as m:
PeriodIndex(start="2000", periods=2)
- warning, = m
+ (warning,) = m
assert 'freq="A-DEC"' in str(warning.message)
def test_constructor(self):
diff --git a/pandas/tests/indexing/multiindex/test_getitem.py b/pandas/tests/indexing/multiindex/test_getitem.py
index 4f95e6bd2..519a1eb5b 100644
--- a/pandas/tests/indexing/multiindex/test_getitem.py
+++ b/pandas/tests/indexing/multiindex/test_getitem.py
@@ -108,7 +108,7 @@ def test_series_getitem_indexing_errors(
def test_series_getitem_corner_generator(
- multiindex_year_month_day_dataframe_random_data
+ multiindex_year_month_day_dataframe_random_data,
):
s = multiindex_year_month_day_dataframe_random_data["A"]
result = s[(x > 0 for x in s)]
diff --git a/pandas/tests/indexing/multiindex/test_xs.py b/pandas/tests/indexing/multiindex/test_xs.py
index 99f343c2f..40483ffec 100644
--- a/pandas/tests/indexing/multiindex/test_xs.py
+++ b/pandas/tests/indexing/multiindex/test_xs.py
@@ -211,7 +211,7 @@ def test_xs_level_series_ymd(multiindex_year_month_day_dataframe_random_data):
def test_xs_level_series_slice_not_implemented(
- multiindex_year_month_day_dataframe_random_data
+ multiindex_year_month_day_dataframe_random_data,
):
# this test is not explicitly testing .xs functionality
# TODO: move to another module or refactor
diff --git a/pandas/tests/indexing/test_callable.py b/pandas/tests/indexing/test_callable.py
index aa73bd728..81dedfdc7 100644
--- a/pandas/tests/indexing/test_callable.py
+++ b/pandas/tests/indexing/test_callable.py
@@ -17,10 +17,14 @@ class TestIndexingCallable:
res = df.loc[lambda x: x.A > 2]
tm.assert_frame_equal(res, df.loc[df.A > 2])
- res = df.loc[lambda x: x.A > 2,] # noqa: E231
+ res = df.loc[
+ lambda x: x.A > 2,
+ ] # noqa: E231
tm.assert_frame_equal(res, df.loc[df.A > 2,]) # noqa: E231
- res = df.loc[lambda x: x.A > 2,] # noqa: E231
+ res = df.loc[
+ lambda x: x.A > 2,
+ ] # noqa: E231
tm.assert_frame_equal(res, df.loc[df.A > 2,]) # noqa: E231
res = df.loc[lambda x: x.B == "b", :]
@@ -90,7 +94,9 @@ class TestIndexingCallable:
res = df.loc[lambda x: ["A", "C"]]
tm.assert_frame_equal(res, df.loc[["A", "C"]])
- res = df.loc[lambda x: ["A", "C"],] # noqa: E231
+ res = df.loc[
+ lambda x: ["A", "C"],
+ ] # noqa: E231
tm.assert_frame_equal(res, df.loc[["A", "C"],]) # noqa: E231
res = df.loc[lambda x: ["A", "C"], :]
diff --git a/pandas/tests/io/parser/test_index_col.py b/pandas/tests/io/parser/test_index_col.py
index 4dfb8d3bd..812255999 100644
--- a/pandas/tests/io/parser/test_index_col.py
+++ b/pandas/tests/io/parser/test_index_col.py
@@ -22,8 +22,8 @@ KORD4,19990127, 21:00:00, 21:18:00, -0.9900, 2.0100, 3.6000, 0.0000, 270.0000
KORD5,19990127, 22:00:00, 21:56:00, -0.5900, 1.7100, 5.1000, 0.0000, 290.0000
KORD6,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000""" # noqa
header = (
- "ID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir\n"
- ) # noqa
+ "ID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir\n" # noqa
+ )
if with_header:
data = header + no_header
diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py
index 05ebff438..9bd6fb41c 100644
--- a/pandas/tests/reductions/test_reductions.py
+++ b/pandas/tests/reductions/test_reductions.py
@@ -179,8 +179,8 @@ class TestIndexReductions:
[
(0, 400, 3),
(500, 0, -6),
- (-10 ** 6, 10 ** 6, 4),
- (10 ** 6, -10 ** 6, -4),
+ (-(10 ** 6), 10 ** 6, 4),
+ (10 ** 6, -(10 ** 6), -4),
(0, 10, 20),
],
)
diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py
index 9dd88fd5d..885428e51 100644
--- a/pandas/tests/test_algos.py
+++ b/pandas/tests/test_algos.py
@@ -216,10 +216,10 @@ class TestFactorize:
tm.assert_numpy_array_equal(uniques, exp_uniques)
def test_int64_factorize(self, writable):
- data = np.array([2 ** 63 - 1, -2 ** 63, 2 ** 63 - 1], dtype=np.int64)
+ data = np.array([2 ** 63 - 1, -(2 ** 63), 2 ** 63 - 1], dtype=np.int64)
data.setflags(write=writable)
exp_labels = np.array([0, 1, 0], dtype=np.intp)
- exp_uniques = np.array([2 ** 63 - 1, -2 ** 63], dtype=np.int64)
+ exp_uniques = np.array([2 ** 63 - 1, -(2 ** 63)], dtype=np.int64)
labels, uniques = algos.factorize(data)
tm.assert_numpy_array_equal(labels, exp_labels)
@@ -258,7 +258,7 @@ class TestFactorize:
"data",
[
np.array([0, 1, 0], dtype="u8"),
- np.array([-2 ** 63, 1, -2 ** 63], dtype="i8"),
+ np.array([-(2 ** 63), 1, -(2 ** 63)], dtype="i8"),
np.array(["__nan__", "foo", "__nan__"], dtype="object"),
],
)
@@ -275,8 +275,8 @@ class TestFactorize:
[
(np.array([0, 1, 0, 2], dtype="u8"), 0),
(np.array([1, 0, 1, 2], dtype="u8"), 1),
- (np.array([-2 ** 63, 1, -2 ** 63, 0], dtype="i8"), -2 ** 63),
- (np.array([1, -2 ** 63, 1, 0], dtype="i8"), 1),
+ (np.array([-(2 ** 63), 1, -(2 ** 63), 0], dtype="i8"), -(2 ** 63)),
+ (np.array([1, -(2 ** 63), 1, 0], dtype="i8"), 1),
(np.array(["a", "", "a", "b"], dtype=object), "a"),
(np.array([(), ("a", 1), (), ("a", 2)], dtype=object), ()),
(np.array([("a", 1), (), ("a", 1), ("a", 2)], dtype=object), ("a", 1)),
diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py
index 49d1777df..e6cff5c26 100644
--- a/pandas/tests/test_nanops.py
+++ b/pandas/tests/test_nanops.py
@@ -302,7 +302,7 @@ class TestnanopsDataFrame:
# In the previous implementation mean can overflow for int dtypes, it
# is now consistent with numpy
- for a in [2 ** 55, -2 ** 55, 20150515061816532]:
+ for a in [2 ** 55, -(2 ** 55), 20150515061816532]:
s = Series(a, index=range(500), dtype=np.int64)
result = s.mean()
np_result = s.values.mean()
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 0de9955
python : 3.7.4.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.26.0.dev0+734.g0de99558b
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 41.6.0
Cython : 0.29.14
pytest : 5.2.2
hypothesis : 4.42.6
sphinx : 2.2.1
blosc : 1.8.1
feather : None
xlsxwriter : None
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : 0.3.2
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : 3.6.1
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None