Skip to content

STY: concat strings #30979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
raise ImportError(
f"C extension: {module} not built. If you want to import "
"pandas from the source directory, you may need to run "
"'python setup.py build_ext --inplace --force' to build "
"the C extensions first."
"'python setup.py build_ext --inplace --force' to build the C extensions first."
)

from pandas._config import (
Expand Down Expand Up @@ -198,8 +197,7 @@ def __getattr__(name):

warnings.warn(
"The Panel class is removed from pandas. Accessing it "
"from the top-level namespace will also be removed in "
"the next version",
"from the top-level namespace will also be removed in the next version",
FutureWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -238,8 +236,7 @@ class Panel:
elif name in {"SparseSeries", "SparseDataFrame"}:
warnings.warn(
f"The {name} class is removed from pandas. Accessing it from "
"the top-level namespace will also be removed in the next "
"version",
"the top-level namespace will also be removed in the next version",
FutureWarning,
stacklevel=2,
)
Expand Down
3 changes: 1 addition & 2 deletions pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ def _reset_option(pat, silent=False):
raise ValueError(
"You must specify at least 4 characters when "
"resetting multiple keys, use the special keyword "
'"all" to reset all the options to their default '
"value"
'"all" to reset all the options to their default value'
)

for k in keys:
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ def to_series(right):

elif right.ndim > 2:
raise ValueError(
"Unable to coerce to Series/DataFrame, dim "
f"must be <= 2: {right.shape}"
f"Unable to coerce to Series/DataFrame, dim must be <= 2: {right.shape}"
)

elif is_list_like(right) and not isinstance(right, (ABCSeries, ABCDataFrame)):
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def melt(
if not missing.empty:
raise KeyError(
"The following 'id_vars' are not present "
"in the DataFrame: {missing}"
"".format(missing=list(missing))
f"in the DataFrame: {list(missing)}"
)
else:
id_vars = []
Expand All @@ -74,8 +73,7 @@ def melt(
if not missing.empty:
raise KeyError(
"The following 'value_vars' are not present in "
"the DataFrame: {missing}"
"".format(missing=list(missing))
f"the DataFrame: {list(missing)}"
)
frame = frame.loc[:, id_vars + value_vars]
else:
Expand Down
34 changes: 11 additions & 23 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,11 @@ def __init__(

if not is_bool(left_index):
raise ValueError(
"left_index parameter must be of type bool, not "
"{left_index}".format(left_index=type(left_index))
f"left_index parameter must be of type bool, not {type(left_index)}"
)
if not is_bool(right_index):
raise ValueError(
"right_index parameter must be of type bool, not "
"{right_index}".format(right_index=type(right_index))
f"right_index parameter must be of type bool, not {type(right_index)}"
)

# warn user when merging between different levels
Expand Down Expand Up @@ -1092,8 +1090,7 @@ def _maybe_coerce_merge_keys(self):
warnings.warn(
"You are merging on int and float "
"columns where the float values "
"are not equal to their int "
"representation",
"are not equal to their int representation",
UserWarning,
)
continue
Expand All @@ -1103,8 +1100,7 @@ def _maybe_coerce_merge_keys(self):
warnings.warn(
"You are merging on int and float "
"columns where the float values "
"are not equal to their int "
"representation",
"are not equal to their int representation",
UserWarning,
)
continue
Expand Down Expand Up @@ -1251,20 +1247,17 @@ def _validate(self, validate: str):
)
elif not left_unique:
raise MergeError(
"Merge keys are not unique in left dataset; "
"not a one-to-one merge"
"Merge keys are not unique in left dataset; not a one-to-one merge"
)
elif not right_unique:
raise MergeError(
"Merge keys are not unique in right dataset; "
"not a one-to-one merge"
"Merge keys are not unique in right dataset; not a one-to-one merge"
)

elif validate in ["one_to_many", "1:m"]:
if not left_unique:
raise MergeError(
"Merge keys are not unique in left dataset; "
"not a one-to-many merge"
"Merge keys are not unique in left dataset; not a one-to-many merge"
)

elif validate in ["many_to_one", "m:1"]:
Expand Down Expand Up @@ -1833,8 +1826,7 @@ def _left_join_on_index(left_ax: Index, right_ax: Index, join_keys, sort: bool =
raise AssertionError(
"If more than one join key is given then "
"'right_ax' must be a MultiIndex and the "
"number of join keys must be the number of "
"levels in right_ax"
"number of join keys must be the number of levels in right_ax"
)

left_indexer, right_indexer = _get_multiindex_indexer(
Expand Down Expand Up @@ -2004,8 +1996,7 @@ def _validate_operand(obj: FrameOrSeries) -> "DataFrame":
return obj.to_frame()
else:
raise TypeError(
"Can only merge Series or DataFrame objects, "
"a {obj} was passed".format(obj=type(obj))
f"Can only merge Series or DataFrame objects, a {type(obj)} was passed"
)


Expand All @@ -2021,10 +2012,7 @@ def _items_overlap_with_suffix(left: Index, lsuffix, right: Index, rsuffix):
return left, right

if not lsuffix and not rsuffix:
raise ValueError(
"columns overlap but no suffix specified: "
"{rename}".format(rename=to_rename)
)
raise ValueError(f"columns overlap but no suffix specified: {to_rename}")

def renamer(x, suffix):
"""
Expand All @@ -2043,7 +2031,7 @@ def renamer(x, suffix):
x : renamed column name
"""
if x in to_rename and suffix is not None:
return "{x}{suffix}".format(x=x, suffix=suffix)
return f"{x}{suffix}"
return x

lrenamer = partial(renamer, suffix=lsuffix)
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/reshape/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ def _bins_to_cuts(

if duplicates not in ["raise", "drop"]:
raise ValueError(
"invalid value for 'duplicates' parameter, "
"valid options are: raise, drop"
"invalid value for 'duplicates' parameter, valid options are: raise, drop"
)

if isinstance(bins, IntervalIndex):
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def _return_parsed_timezone_results(result, timezones, tz, name):
"""
if tz is not None:
raise ValueError(
"Cannot pass a tz argument when "
"parsing strings with timezone "
"information."
"Cannot pass a tz argument when parsing strings with timezone information."
)
tz_results = np.array(
[Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezones)]
Expand Down Expand Up @@ -817,8 +815,7 @@ def f(value):
required = ",".join(req)
raise ValueError(
"to assemble mappings requires at least that "
f"[year, month, day] be specified: [{required}] "
"is missing"
f"[year, month, day] be specified: [{required}] is missing"
)

# keys we don't recognize
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/window/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ def _flex_binary_moment(arg1, arg2, f, pairwise=False):
and isinstance(arg2, (np.ndarray, ABCSeries, ABCDataFrame))
):
raise TypeError(
"arguments to moment function must be of type "
"np.ndarray/Series/DataFrame"
"arguments to moment function must be of type np.ndarray/Series/DataFrame"
)

if isinstance(arg1, (np.ndarray, ABCSeries)) and isinstance(
Expand Down
11 changes: 4 additions & 7 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,7 @@ def _on(self) -> Index:
else:
raise ValueError(
f"invalid on specified as {self.on}, "
"must be a column (of DataFrame), an Index "
"or None"
"must be a column (of DataFrame), an Index or None"
)

def validate(self):
Expand All @@ -1838,9 +1837,8 @@ def validate(self):
# we don't allow center
if self.center:
raise NotImplementedError(
"center is not implemented "
"for datetimelike and offset "
"based windows"
"center is not implemented for "
"datetimelike and offset based windows"
)

# this will raise ValueError on non-fixed freqs
Expand Down Expand Up @@ -1886,8 +1884,7 @@ def _validate_freq(self):
except (TypeError, ValueError):
raise ValueError(
f"passed window {self.window} is not "
"compatible with a datetimelike "
"index"
"compatible with a datetimelike index"
)

_agg_see_also_doc = dedent(
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/excel/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def _maybe_convert_usecols(usecols):
if is_integer(usecols):
raise ValueError(
"Passing an integer for `usecols` is no longer supported. "
"Please pass in a list of int from 0 to `usecols` "
"inclusive instead."
"Please pass in a list of int from 0 to `usecols` inclusive instead."
)

if isinstance(usecols, str):
Expand Down
8 changes: 2 additions & 6 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,8 @@ def _to_str_columns(self) -> List[List[str]]:
self.header = cast(List[str], self.header)
if len(self.header) != len(self.columns):
raise ValueError(
(
"Writing {ncols} cols but got {nalias} "
"aliases".format(
ncols=len(self.columns), nalias=len(self.header)
)
)
f"Writing {len(self.columns)} cols "
f"but got {len(self.header)} aliases"
)
str_columns = [[label] for label in self.header]
else:
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ def _write_table(self, indent: int = 0) -> None:
self.classes = self.classes.split()
if not isinstance(self.classes, (list, tuple)):
raise TypeError(
"classes must be a string, list, or tuple, "
"not {typ}".format(typ=type(self.classes))
"classes must be a string, list, "
f"or tuple, not {type(self.classes)}"
)
_classes.extend(self.classes)

Expand Down
3 changes: 1 addition & 2 deletions pandas/io/formats/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ def pad_empties(x):
column_format = index_format + column_format
elif not isinstance(self.column_format, str): # pragma: no cover
raise AssertionError(
"column_format must be str or unicode, "
"not {typ}".format(typ=type(column_format))
f"column_format must be str or unicode, not {type(column_format)}"
)
else:
column_format = self.column_format
Expand Down
5 changes: 3 additions & 2 deletions pandas/io/sas/sas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ cdef class Parser:
elif column_types[j] == b's':
self.column_types[j] = column_type_string
else:
raise ValueError("unknown column type: "
f"{self.parser.columns[j].ctype}")
raise ValueError(
f"unknown column type: {self.parser.columns[j].ctype}"
)

# compression
if parser.compression == const.rle_compression:
Expand Down
6 changes: 2 additions & 4 deletions pandas/io/sas/sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ def _process_columnsize_subheader(self, offset, length):
if self.col_count_p1 + self.col_count_p2 != self.column_count:
print(
f"Warning: column count mismatch ({self.col_count_p1} + "
f"{self.col_count_p2} != "
f"{self.column_count})\n"
f"{self.col_count_p2} != {self.column_count})\n"
)

# Unknown purpose
Expand Down Expand Up @@ -672,8 +671,7 @@ def _read_next_page(self):
self.close()
msg = (
"failed to read complete page from file (read "
f"{len(self._cached_page):d} of "
f"{self._page_length:d} bytes)"
f"{len(self._cached_page):d} of {self._page_length:d} bytes)"
)
raise ValueError(msg)

Expand Down
3 changes: 1 addition & 2 deletions pandas/io/sas/sasreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def read_sas(
if format is None:
buffer_error_msg = (
"If this is a buffer object rather "
"than a string name, you must specify "
"a format string"
"than a string name, you must specify a format string"
)
filepath_or_buffer = stringify_path(filepath_or_buffer)
if not isinstance(filepath_or_buffer, str):
Expand Down
3 changes: 1 addition & 2 deletions scripts/generate_pip_deps_from_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def main(conda_fname, pip_fname, compare=False):
)
if args.azure:
msg = (
"##vso[task.logissue type=error;"
f"sourcepath=requirements-dev.txt]{msg}"
f"##vso[task.logissue type=error;sourcepath=requirements-dev.txt]{msg}"
)
sys.stderr.write(msg)
sys.exit(res)