Skip to content

Commit e216164

Browse files
author
Mateusz Górski
committed
Fix black pandas
1 parent d045aed commit e216164

24 files changed

+51
-96
lines changed

pandas/core/frame.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -6564,7 +6564,7 @@ def apply(self, func, axis=0, raw=False, result_type=None, args=(), **kwds):
65646564
"""
65656565
from pandas.core.apply import frame_apply
65666566

6567-
#Old apply function, which will be used for each part of DataFrame
6567+
# Old apply function, which will be used for each part of DataFrame
65686568
def partial_apply(dataframe):
65696569
op = frame_apply(
65706570
dataframe,
@@ -6580,7 +6580,7 @@ def partial_apply(dataframe):
65806580
def get_dtype(dataframe, column):
65816581
return dataframe.dtypes.values[column]
65826582

6583-
if axis == 0 or axis == 'index':
6583+
if axis == 0 or axis == "index":
65846584
if self.shape[1] == 0:
65856585
return partial_apply(self)
65866586

@@ -6596,10 +6596,13 @@ def get_dtype(dataframe, column):
65966596
type = get_dtype(self, i)
65976597
j = i + 1
65986598

6599-
#While the dtype of column is the same as previous ones, they are handled together
6600-
while j < self.shape[1] and pandas.core.dtypes.common.is_dtype_equal(type, get_dtype(self, j)):
6599+
# While the dtype of column is the same as previous ones,
6600+
# they are handled together
6601+
while j < self.shape[1] and pandas.core.dtypes.common.is_dtype_equal(
6602+
type, get_dtype(self, j)
6603+
):
66016604
j += 1
6602-
frame = self.iloc[:, i: j]
6605+
frame = self.iloc[:, i:j]
66036606
i = j
66046607
result = partial_apply(frame)
66056608

@@ -6619,7 +6622,6 @@ def get_dtype(dataframe, column):
66196622
else:
66206623
return partial_apply(self)
66216624

6622-
66236625
def applymap(self, func):
66246626
"""
66256627
Apply a function to a Dataframe elementwise.

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def _aggregate_multiple_funcs(self, arg):
318318
return DataFrame(results, columns=columns)
319319

320320
def _wrap_series_output(
321-
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]], index: Index,
321+
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]], index: Index
322322
) -> Union[Series, DataFrame]:
323323
"""
324324
Wraps the output of a SeriesGroupBy operation into the expected result.

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _outer_indexer(self, left, right):
265265
# Constructors
266266

267267
def __new__(
268-
cls, data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs,
268+
cls, data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs
269269
) -> "Index":
270270

271271
from .range import RangeIndex

pandas/core/indexes/category.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,7 @@ def _engine_type(self):
164164
# Constructors
165165

166166
def __new__(
167-
cls,
168-
data=None,
169-
categories=None,
170-
ordered=None,
171-
dtype=None,
172-
copy=False,
173-
name=None,
167+
cls, data=None, categories=None, ordered=None, dtype=None, copy=False, name=None
174168
):
175169

176170
dtype = CategoricalDtype._from_values_or_dtype(data, categories, ordered, dtype)

pandas/core/indexes/range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class RangeIndex(Int64Index):
8181
# Constructors
8282

8383
def __new__(
84-
cls, start=None, stop=None, step=None, dtype=None, copy=False, name=None,
84+
cls, start=None, stop=None, step=None, dtype=None, copy=False, name=None
8585
):
8686

8787
cls._validate_dtype(dtype)

pandas/core/ops/dispatch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def should_series_dispatch(left, right, op):
9595

9696

9797
def dispatch_to_extension_op(
98-
op, left: Union[ABCExtensionArray, np.ndarray], right: Any,
98+
op, left: Union[ABCExtensionArray, np.ndarray], right: Any
9999
):
100100
"""
101101
Assume that left or right is a Series backed by an ExtensionArray,

pandas/core/series.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -4386,9 +4386,7 @@ def to_period(self, freq=None, copy=True):
43864386
hist = pandas.plotting.hist_series
43874387

43884388

4389-
Series._setup_axes(
4390-
["index"], docs={"index": "The index (axis labels) of the Series."},
4391-
)
4389+
Series._setup_axes(["index"], docs={"index": "The index (axis labels) of the Series."})
43924390
Series._add_numeric_operations()
43934391
Series._add_series_only_operations()
43944392
Series._add_series_or_dataframe_operations()

pandas/core/window/indexers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BaseIndexer:
3535
"""Base class for window bounds calculations"""
3636

3737
def __init__(
38-
self, index_array: Optional[np.ndarray] = None, window_size: int = 0, **kwargs,
38+
self, index_array: Optional[np.ndarray] = None, window_size: int = 0, **kwargs
3939
):
4040
"""
4141
Parameters
@@ -100,7 +100,7 @@ def get_window_bounds(
100100
) -> Tuple[np.ndarray, np.ndarray]:
101101

102102
return calculate_variable_window_bounds(
103-
num_values, self.window_size, min_periods, center, closed, self.index_array,
103+
num_values, self.window_size, min_periods, center, closed, self.index_array
104104
)
105105

106106

pandas/io/formats/css.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def expand(self, prop, value):
1717
try:
1818
mapping = self.SIDE_SHORTHANDS[len(tokens)]
1919
except KeyError:
20-
warnings.warn(
21-
f'Could not expand "{prop}: {value}"', CSSWarning,
22-
)
20+
warnings.warn(f'Could not expand "{prop}: {value}"', CSSWarning)
2321
return
2422
for key, idx in zip(self.SIDES, mapping):
2523
yield prop_fmt.format(key), tokens[idx]
@@ -114,10 +112,7 @@ def __call__(self, declarations_str, inherited=None):
114112
props[prop] = self.size_to_pt(
115113
props[prop], em_pt=font_size, conversions=self.BORDER_WIDTH_RATIOS
116114
)
117-
for prop in [
118-
f"margin-{side}",
119-
f"padding-{side}",
120-
]:
115+
for prop in [f"margin-{side}", f"padding-{side}"]:
121116
if prop in props:
122117
# TODO: support %
123118
props[prop] = self.size_to_pt(

pandas/io/formats/excel.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ def build_border(self, props):
133133
return {
134134
side: {
135135
"style": self._border_style(
136-
props.get(f"border-{side}-style"),
137-
props.get(f"border-{side}-width"),
136+
props.get(f"border-{side}-style"), props.get(f"border-{side}-width")
138137
),
139138
"color": self.color_to_excel(props.get(f"border-{side}-color")),
140139
}

pandas/io/formats/style.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,7 @@ def format_attr(pair):
291291

292292
# ... except maybe the last for columns.names
293293
name = self.data.columns.names[r]
294-
cs = [
295-
BLANK_CLASS if name is None else INDEX_NAME_CLASS,
296-
f"level{r}",
297-
]
294+
cs = [BLANK_CLASS if name is None else INDEX_NAME_CLASS, f"level{r}"]
298295
name = BLANK_VALUE if name is None else name
299296
row_es.append(
300297
{
@@ -308,11 +305,7 @@ def format_attr(pair):
308305

309306
if clabels:
310307
for c, value in enumerate(clabels[r]):
311-
cs = [
312-
COL_HEADING_CLASS,
313-
f"level{r}",
314-
f"col{c}",
315-
]
308+
cs = [COL_HEADING_CLASS, f"level{r}", f"col{c}"]
316309
cs.extend(
317310
cell_context.get("col_headings", {}).get(r, {}).get(c, [])
318311
)
@@ -356,11 +349,7 @@ def format_attr(pair):
356349
for r, idx in enumerate(self.data.index):
357350
row_es = []
358351
for c, value in enumerate(rlabels[r]):
359-
rid = [
360-
ROW_HEADING_CLASS,
361-
f"level{c}",
362-
f"row{r}",
363-
]
352+
rid = [ROW_HEADING_CLASS, f"level{c}", f"row{r}"]
364353
es = {
365354
"type": "th",
366355
"is_visible": (_is_visible(r, c, idx_lengths) and not hidden_index),

pandas/io/orc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def read_orc(
15-
path: FilePathOrBuffer, columns: Optional[List[str]] = None, **kwargs,
15+
path: FilePathOrBuffer, columns: Optional[List[str]] = None, **kwargs
1616
) -> "DataFrame":
1717
"""
1818
Load an ORC object from the file path, returning a DataFrame.

pandas/io/pytables.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ class DuplicateWarning(Warning):
177177
_FORMAT_MAP = {"f": "fixed", "fixed": "fixed", "t": "table", "table": "table"}
178178

179179
# storer class map
180-
_STORER_MAP = {
181-
"series": "SeriesFixed",
182-
"frame": "FrameFixed",
183-
}
180+
_STORER_MAP = {"series": "SeriesFixed", "frame": "FrameFixed"}
184181

185182
# table class map
186183
_TABLE_MAP = {
@@ -2863,7 +2860,7 @@ def read_index_node(
28632860
# If the index was an empty array write_array_empty() will
28642861
# have written a sentinel. Here we relace it with the original.
28652862
if "shape" in node._v_attrs and np.prod(node._v_attrs.shape) == 0:
2866-
data = np.empty(node._v_attrs.shape, dtype=node._v_attrs.value_type,)
2863+
data = np.empty(node._v_attrs.shape, dtype=node._v_attrs.value_type)
28672864
kind = _ensure_decoded(node._v_attrs.kind)
28682865
name = None
28692866

@@ -3600,10 +3597,7 @@ def _read_axes(
36003597
for a in self.axes:
36013598
a.set_info(self.info)
36023599
res = a.convert(
3603-
values,
3604-
nan_rep=self.nan_rep,
3605-
encoding=self.encoding,
3606-
errors=self.errors,
3600+
values, nan_rep=self.nan_rep, encoding=self.encoding, errors=self.errors
36073601
)
36083602
results.append(res)
36093603

@@ -3995,7 +3989,7 @@ def create_description(
39953989
return d
39963990

39973991
def read_coordinates(
3998-
self, where=None, start: Optional[int] = None, stop: Optional[int] = None,
3992+
self, where=None, start: Optional[int] = None, stop: Optional[int] = None
39993993
):
40003994
"""select coordinates (row numbers) from a table; return the
40013995
coordinates object
@@ -4262,7 +4256,7 @@ def write_data_chunk(
42624256
self.table.flush()
42634257

42644258
def delete(
4265-
self, where=None, start: Optional[int] = None, stop: Optional[int] = None,
4259+
self, where=None, start: Optional[int] = None, stop: Optional[int] = None
42664260
):
42674261

42684262
# delete all rows (and return the nrows)
@@ -4691,7 +4685,7 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
46914685
if inferred_type == "date":
46924686
converted = np.asarray([v.toordinal() for v in values], dtype=np.int32)
46934687
return IndexCol(
4694-
name, converted, "date", _tables().Time32Col(), index_name=index_name,
4688+
name, converted, "date", _tables().Time32Col(), index_name=index_name
46954689
)
46964690
elif inferred_type == "string":
46974691

@@ -4707,13 +4701,13 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
47074701

47084702
elif inferred_type in ["integer", "floating"]:
47094703
return IndexCol(
4710-
name, values=converted, kind=kind, typ=atom, index_name=index_name,
4704+
name, values=converted, kind=kind, typ=atom, index_name=index_name
47114705
)
47124706
else:
47134707
assert isinstance(converted, np.ndarray) and converted.dtype == object
47144708
assert kind == "object", kind
47154709
atom = _tables().ObjectAtom()
4716-
return IndexCol(name, converted, kind, atom, index_name=index_name,)
4710+
return IndexCol(name, converted, kind, atom, index_name=index_name)
47174711

47184712

47194713
def _unconvert_index(

pandas/tests/arithmetic/test_numeric.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TestNumericArraylikeArithmeticWithDatetimeLike:
9595
# TODO: also check name retentention
9696
@pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series])
9797
@pytest.mark.parametrize(
98-
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype),
98+
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype)
9999
)
100100
def test_mul_td64arr(self, left, box_cls):
101101
# GH#22390
@@ -115,7 +115,7 @@ def test_mul_td64arr(self, left, box_cls):
115115
# TODO: also check name retentention
116116
@pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series])
117117
@pytest.mark.parametrize(
118-
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype),
118+
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype)
119119
)
120120
def test_div_td64arr(self, left, box_cls):
121121
# GH#22390

pandas/tests/arrays/sparse/test_array.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -660,16 +660,12 @@ def test_getslice_tuple(self):
660660
dense = np.array([np.nan, 0, 3, 4, 0, 5, np.nan, np.nan, 0])
661661

662662
sparse = SparseArray(dense)
663-
res = sparse[
664-
4:,
665-
] # noqa: E231
663+
res = sparse[4:,] # noqa: E231
666664
exp = SparseArray(dense[4:,]) # noqa: E231
667665
tm.assert_sp_array_equal(res, exp)
668666

669667
sparse = SparseArray(dense, fill_value=0)
670-
res = sparse[
671-
4:,
672-
] # noqa: E231
668+
res = sparse[4:,] # noqa: E231
673669
exp = SparseArray(dense[4:,], fill_value=0) # noqa: E231
674670
tm.assert_sp_array_equal(res, exp)
675671

pandas/tests/arrays/test_boolean.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,7 @@ def test_kleene_xor_scalar(self, other, expected):
565565
a, pd.array([True, False, None], dtype="boolean")
566566
)
567567

568-
@pytest.mark.parametrize(
569-
"other", [True, False, pd.NA, [True, False, None] * 3],
570-
)
568+
@pytest.mark.parametrize("other", [True, False, pd.NA, [True, False, None] * 3])
571569
def test_no_masked_assumptions(self, other, all_logical_operators):
572570
# The logical operations should not assume that masked values are False!
573571
a = pd.arrays.BooleanArray(

pandas/tests/frame/test_apply.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,8 @@ def test_apply_dup_names_multi_agg(self):
693693

694694
def test_apply_get_dtype(self):
695695
# GH 28773
696-
df = DataFrame({
697-
"col_1": [1, 2, 3],
698-
"col_2": ["hi", "there", "friend"]
699-
})
700-
expected = Series(data=['int64', 'object'] ,index=['col_1', 'col_2'])
696+
df = DataFrame({"col_1": [1, 2, 3], "col_2": ["hi", "there", "friend"]})
697+
expected = Series(data=["int64", "object"], index=["col_1", "col_2"])
701698
tm.assert_series_equal(df.apply(lambda x: x.dtype), expected)
702699

703700

pandas/tests/indexing/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def check_values(self, f, func, values=False):
170170
tm.assert_almost_equal(result, expected)
171171

172172
def check_result(
173-
self, method1, key1, method2, key2, typs=None, axes=None, fails=None,
173+
self, method1, key1, method2, key2, typs=None, axes=None, fails=None
174174
):
175175
def _eq(axis, obj, key1, key2):
176176
""" compare equal for these 2 keys """

pandas/tests/indexing/test_callable.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ def test_frame_loc_callable(self):
1717
res = df.loc[lambda x: x.A > 2]
1818
tm.assert_frame_equal(res, df.loc[df.A > 2])
1919

20-
res = df.loc[
21-
lambda x: x.A > 2,
22-
] # noqa: E231
20+
res = df.loc[lambda x: x.A > 2,] # noqa: E231
2321
tm.assert_frame_equal(res, df.loc[df.A > 2,]) # noqa: E231
2422

25-
res = df.loc[
26-
lambda x: x.A > 2,
27-
] # noqa: E231
23+
res = df.loc[lambda x: x.A > 2,] # noqa: E231
2824
tm.assert_frame_equal(res, df.loc[df.A > 2,]) # noqa: E231
2925

3026
res = df.loc[lambda x: x.B == "b", :]
@@ -94,9 +90,7 @@ def test_frame_loc_callable_labels(self):
9490
res = df.loc[lambda x: ["A", "C"]]
9591
tm.assert_frame_equal(res, df.loc[["A", "C"]])
9692

97-
res = df.loc[
98-
lambda x: ["A", "C"],
99-
] # noqa: E231
93+
res = df.loc[lambda x: ["A", "C"],] # noqa: E231
10094
tm.assert_frame_equal(res, df.loc[["A", "C"],]) # noqa: E231
10195

10296
res = df.loc[lambda x: ["A", "C"], :]

pandas/tests/indexing/test_loc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_loc_getitem_label_out_of_range(self):
116116
self.check_result("loc", "f", "ix", "f", typs=["floats"], fails=KeyError)
117117
self.check_result("loc", "f", "loc", "f", typs=["floats"], fails=KeyError)
118118
self.check_result(
119-
"loc", 20, "loc", 20, typs=["ints", "uints", "mixed"], fails=KeyError,
119+
"loc", 20, "loc", 20, typs=["ints", "uints", "mixed"], fails=KeyError
120120
)
121121
self.check_result("loc", 20, "loc", 20, typs=["labels"], fails=TypeError)
122122
self.check_result("loc", 20, "loc", 20, typs=["ts"], axes=0, fails=TypeError)
@@ -129,7 +129,7 @@ def test_loc_getitem_label_list(self):
129129

130130
def test_loc_getitem_label_list_with_missing(self):
131131
self.check_result(
132-
"loc", [0, 1, 2], "loc", [0, 1, 2], typs=["empty"], fails=KeyError,
132+
"loc", [0, 1, 2], "loc", [0, 1, 2], typs=["empty"], fails=KeyError
133133
)
134134
self.check_result(
135135
"loc",

0 commit comments

Comments
 (0)