Skip to content

STY: concat strings #30991

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 1 commit into from
Jan 14, 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
3 changes: 1 addition & 2 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def _import_lzma():
return lzma
except ImportError:
msg = (
"Could not import the lzma module. "
"Your installed Python is incomplete. "
"Could not import the lzma module. Your installed Python is incomplete. "
"Attempting to use lzma compression will result in a RuntimeError."
)
warnings.warn(msg)
Expand Down
6 changes: 2 additions & 4 deletions pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

if _nlv < "1.13.3":
raise ImportError(
f"this version of pandas is incompatible with "
f"numpy < 1.13.3\n"
"this version of pandas is incompatible with numpy < 1.13.3\n"
f"your numpy version is {_np_version}.\n"
f"Please upgrade numpy to >= 1.13.3 to use "
f"this pandas version"
"Please upgrade numpy to >= 1.13.3 to use this pandas version"
)


Expand Down
5 changes: 2 additions & 3 deletions pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,8 @@ def validate_resampler_func(method: str, args, kwargs) -> None:
if len(args) + len(kwargs) > 0:
if method in RESAMPLER_NUMPY_OPS:
raise UnsupportedFunctionCall(
f"numpy operations are not "
f"valid with resample. Use "
f".resample(...).{method}() instead"
"numpy operations are not valid with resample. "
f"Use .resample(...).{method}() instead"
)
else:
raise TypeError("too many arguments passed in")
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,7 @@ def _get_label_or_level_values(self, key: str, axis: int = 0) -> np.ndarray:
multi_message = (
"\n"
"For a multi-index, the label must be a "
"tuple with elements corresponding to "
"each level."
"tuple with elements corresponding to each level."
)
else:
multi_message = ""
Expand Down
11 changes: 3 additions & 8 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ def __init__(
if isinstance(objs, (NDFrame, str)):
raise TypeError(
"first argument must be an iterable of pandas "
"objects, you passed an object of type "
'"{name}"'.format(name=type(objs).__name__)
f'objects, you passed an object of type "{type(objs).__name__}"'
)

if join == "outer":
Expand Down Expand Up @@ -577,10 +576,7 @@ def _maybe_check_integrity(self, concat_index: Index):
if self.verify_integrity:
if not concat_index.is_unique:
overlap = concat_index[concat_index.duplicated()].unique()
raise ValueError(
"Indexes have overlapping values: "
"{overlap!s}".format(overlap=overlap)
)
raise ValueError(f"Indexes have overlapping values: {overlap}")


def _concat_indexes(indexes) -> Index:
Expand Down Expand Up @@ -648,8 +644,7 @@ def _make_concat_multiindex(indexes, keys, levels=None, names=None) -> MultiInde
# make sure that all of the passed indices have the same nlevels
if not len({idx.nlevels for idx in indexes}) == 1:
raise AssertionError(
"Cannot concat indices that do "
"not have the same number of levels"
"Cannot concat indices that do not have the same number of levels"
)

# also copies
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,8 @@ def _maybe_coerce_merge_keys(self):
continue

msg = (
"You are trying to merge on {lk_dtype} and "
"{rk_dtype} columns. If you wish to proceed "
"you should use pd.concat".format(lk_dtype=lk.dtype, rk_dtype=rk.dtype)
f"You are trying to merge on {lk.dtype} and "
f"{rk.dtype} columns. If you wish to proceed you should use pd.concat"
)

# if we are numeric, then allow differing
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/clipboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def read_clipboard(sep=r"\s+", **kwargs): # pragma: no cover
kwargs["engine"] = "python"
elif len(sep) > 1 and kwargs.get("engine") == "c":
warnings.warn(
"read_clipboard with regex separator does not work "
"properly with c engine"
"read_clipboard with regex separator does not work properly with c engine"
)

return read_csv(StringIO(text), sep=sep, **kwargs)
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def _expand_user(
def validate_header_arg(header) -> None:
if isinstance(header, bool):
raise TypeError(
"Passing a bool to header is invalid. "
"Use header=None for no header or "
"Passing a bool to header is invalid. Use header=None for no header or "
"header=int or list-like of ints to specify "
"the row(s) making up the column names"
)
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/date_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def _check_columns(cols):
for i, n in enumerate(map(len, tail)):
if n != N:
raise AssertionError(
f"All columns must have the same length: {N}; "
f"column {i} has length {n}"
f"All columns must have the same length: {N}; column {i} has length {n}"
)

return N
9 changes: 3 additions & 6 deletions pandas/io/feather_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ def to_feather(df: DataFrame, path):
typ = type(df.index)
raise ValueError(
f"feather does not support serializing {typ} "
"for the index; you can .reset_index() "
"to make the index into column(s)"
"for the index; you can .reset_index() to make the index into column(s)"
)

if not df.index.equals(RangeIndex.from_range(range(len(df)))):
raise ValueError(
"feather does not support serializing a "
"non-default index for the index; you "
"can .reset_index() to make the index "
"into column(s)"
"feather does not support serializing a non-default index for the index; "
"you can .reset_index() to make the index into column(s)"
)

if df.index.name is not None:
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,7 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs):
f"The flavor {flav} failed to parse your input. "
"Since you passed a non-rewindable file "
"object, we can't rewind it to try "
"another parser. Try read_html() with a "
"different flavor."
"another parser. Try read_html() with a different flavor."
)

retained = caught
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/json/_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ def _recursive_extract(data, path, seen_meta, level=0):
meta_val = np.nan
else:
raise KeyError(
"Try running with "
"errors='ignore' as key "
"Try running with errors='ignore' as key "
f"{e} is not always present"
)
meta_vals[key].append(meta_val)
Expand Down
6 changes: 2 additions & 4 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def get_engine(engine: str) -> "BaseImpl":
raise ImportError(
"Unable to find a usable engine; "
"tried using: 'pyarrow', 'fastparquet'.\n"
"pyarrow or fastparquet is required for parquet "
"support"
"pyarrow or fastparquet is required for parquet support"
)

if engine == "pyarrow":
Expand Down Expand Up @@ -156,8 +155,7 @@ def write(
if "partition_on" in kwargs and partition_cols is not None:
raise ValueError(
"Cannot use both partition_on and "
"partition_cols. Use partition_cols for "
"partitioning data"
"partition_cols. Use partition_cols for partitioning data"
)
elif "partition_on" in kwargs:
partition_cols = kwargs.pop("partition_on")
Expand Down
26 changes: 9 additions & 17 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ def parser_f(
if delim_whitespace and delimiter != default_sep:
raise ValueError(
"Specified a delimiter with both sep and "
"delim_whitespace=True; you can only "
"specify one."
"delim_whitespace=True; you can only specify one."
)

if engine is not None:
Expand Down Expand Up @@ -968,8 +967,7 @@ def _clean_options(self, options, engine):
fallback_reason = (
"the 'c' engine does not support "
"regex separators (separators > 1 char and "
r"different from '\s+' are "
"interpreted as regex)"
r"different from '\s+' are interpreted as regex)"
)
engine = "python"
elif delim_whitespace:
Expand Down Expand Up @@ -1000,8 +998,7 @@ def _clean_options(self, options, engine):
fallback_reason = (
"ord(quotechar) > 127, meaning the "
"quotechar is larger than one byte, "
"and the 'c' engine does not support "
"such quotechars"
"and the 'c' engine does not support such quotechars"
)
engine = "python"

Expand Down Expand Up @@ -1119,9 +1116,8 @@ def _make_engine(self, engine="c"):
klass = FixedWidthFieldParser
else:
raise ValueError(
f"Unknown engine: {engine} (valid options are "
'"c", "python", or '
'"python-fwf")'
f"Unknown engine: {engine} (valid options "
'are "c", "python", or "python-fwf")'
)
self._engine = klass(self.f, **self.options)

Expand Down Expand Up @@ -1230,8 +1226,7 @@ def _validate_usecols_names(usecols, names):
missing = [c for c in usecols if c not in names]
if len(missing) > 0:
raise ValueError(
"Usecols do not match columns, "
f"columns expected but not found: {missing}"
f"Usecols do not match columns, columns expected but not found: {missing}"
)

return usecols
Expand Down Expand Up @@ -1325,8 +1320,7 @@ def _validate_parse_dates_arg(parse_dates):
that is the case.
"""
msg = (
"Only booleans, lists, and "
"dictionaries are accepted "
"Only booleans, lists, and dictionaries are accepted "
"for the 'parse_dates' parameter"
)

Expand Down Expand Up @@ -1680,8 +1674,7 @@ def _convert_to_ndarrays(
warnings.warn(
(
"Both a converter and dtype were specified "
f"for column {c} - only the converter will "
"be used"
f"for column {c} - only the converter will be used"
),
ParserWarning,
stacklevel=7,
Expand Down Expand Up @@ -1826,8 +1819,7 @@ def _cast_types(self, values, cast_type, column):
except NotImplementedError:
raise NotImplementedError(
f"Extension Array: {array_type} must implement "
"_from_sequence_of_strings in order "
"to be used in parser methods"
"_from_sequence_of_strings in order to be used in parser methods"
)

else:
Expand Down
19 changes: 7 additions & 12 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ def read_hdf(
for group_to_check in groups[1:]:
if not _is_metadata_of(group_to_check, candidate_only_group):
raise ValueError(
"key must be provided when HDF5 file "
"contains multiple datasets."
"key must be provided when HDF5 "
"file contains multiple datasets."
)
key = candidate_only_group._v_pathname
return store.select(
Expand Down Expand Up @@ -1240,8 +1240,7 @@ def append_to_multiple(
if v is None:
if remain_key is not None:
raise ValueError(
"append_to_multiple can only have one value in d that "
"is None"
"append_to_multiple can only have one value in d that is None"
)
remain_key = k
else:
Expand Down Expand Up @@ -2313,8 +2312,7 @@ def validate_attr(self, append):
existing_dtype = getattr(self.attrs, self.dtype_attr, None)
if existing_dtype is not None and existing_dtype != self.dtype:
raise ValueError(
"appended items dtype do not match existing "
"items dtype in table!"
"appended items dtype do not match existing items dtype in table!"
)

def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str):
Expand Down Expand Up @@ -2680,14 +2678,12 @@ def validate_read(self, columns, where):
if columns is not None:
raise TypeError(
"cannot pass a column specification when reading "
"a Fixed format store. this store must be "
"selected in its entirety"
"a Fixed format store. this store must be selected in its entirety"
)
if where is not None:
raise TypeError(
"cannot pass a where specification when reading "
"from a Fixed format store. this store must be "
"selected in its entirety"
"from a Fixed format store. this store must be selected in its entirety"
)

@property
Expand Down Expand Up @@ -2908,8 +2904,7 @@ def write_array(self, key: str, value: ArrayLike, items: Optional[Index] = None)

if is_categorical_dtype(value):
raise NotImplementedError(
"Cannot store a category dtype in "
"a HDF5 dataset that uses format="
"Cannot store a category dtype in a HDF5 dataset that uses format="
'"fixed". Use format="table".'
)
if not empty_array:
Expand Down
9 changes: 3 additions & 6 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,7 @@ def _sqlalchemy_type(self, col):
if col_type == "timedelta64":
warnings.warn(
"the 'timedelta' type is not supported, and will be "
"written as integer values (ns frequency) to the "
"database.",
"written as integer values (ns frequency) to the database.",
UserWarning,
stacklevel=8,
)
Expand Down Expand Up @@ -1413,8 +1412,7 @@ def _get_valid_sqlite_name(name):

_SAFE_NAMES_WARNING = (
"The spaces in these column names will not be changed. "
"In pandas versions < 0.14, spaces were converted to "
"underscores."
"In pandas versions < 0.14, spaces were converted to underscores."
)


Expand Down Expand Up @@ -1528,8 +1526,7 @@ def _sql_type_name(self, col):
if col_type == "timedelta64":
warnings.warn(
"the 'timedelta' type is not supported, and will be "
"written as integer values (ns frequency) to the "
"database.",
"written as integer values (ns frequency) to the database.",
UserWarning,
stacklevel=8,
)
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,7 @@ def __init__(self, catarray, encoding="latin-1"):
if self.text_len > 32000:
raise ValueError(
"Stata value labels for a single variable must "
"have a combined length less than 32,000 "
"characters."
"have a combined length less than 32,000 characters."
)

# Ensure int32
Expand Down Expand Up @@ -1729,9 +1728,10 @@ def _do_select_columns(self, data, columns):
raise ValueError("columns contains duplicate entries")
unmatched = column_set.difference(data.columns)
if unmatched:
joined = ", ".join(list(unmatched))
raise ValueError(
"The following columns were not found in the "
"Stata data set: " + ", ".join(list(unmatched))
"The following columns were not "
f"found in the Stata data set: {joined}"
)
# Copy information for retained columns for later processing
dtyplist = []
Expand Down
3 changes: 1 addition & 2 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ def __call__(self):
if estimate > self.MAXTICKS * 2:
raise RuntimeError(
"MillisecondLocator estimated to generate "
f"{estimate:d} ticks from {dmin} to {dmax}: "
"exceeds Locator.MAXTICKS"
f"{estimate:d} ticks from {dmin} to {dmax}: exceeds Locator.MAXTICKS"
f"* 2 ({self.MAXTICKS * 2:d}) "
)

Expand Down
3 changes: 1 addition & 2 deletions pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ def hist_series(
if "figure" in kwds:
raise ValueError(
"Cannot pass 'figure' when using the "
"'by' argument, since a new 'Figure' instance "
"will be created"
"'by' argument, since a new 'Figure' instance will be created"
)
axes = _grouped_hist(
self,
Expand Down
Loading