Skip to content

CLN: all the things #27647

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 3 commits into from
Jul 30, 2019
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
4 changes: 2 additions & 2 deletions pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _set_option(*args, **kwargs):
# must at least 1 arg deal with constraints later
nargs = len(args)
if not nargs or nargs % 2 != 0:
raise ValueError("Must provide an even number of non-keyword " "arguments")
raise ValueError("Must provide an even number of non-keyword arguments")

# default to false
silent = kwargs.pop("silent", False)
Expand Down Expand Up @@ -395,7 +395,7 @@ class option_context:
def __init__(self, *args):
if not (len(args) % 2 == 0 and len(args) >= 2):
raise ValueError(
"Need to invoke as" " option_context(pat, val, [(pat, val), ...])."
"Need to invoke as option_context(pat, val, [(pat, val), ...])."
)

self.ops = list(zip(args[::2], args[1::2]))
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __call__(self, args, kwargs, fname=None, max_fname_arg_count=None, method=No
)
else:
raise ValueError(
"invalid validation method " "'{method}'".format(method=method)
"invalid validation method '{method}'".format(method=method)
)


Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def _generate_range(
if start is None and end is None:
if closed is not None:
raise ValueError(
"Closed has to be None if not both of startand end are defined"
"Closed has to be None if not both of start and end are defined"
)
if start is NaT or end is NaT:
raise ValueError("Neither `start` nor `end` can be NaT")
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def aggregate(self, func, *args, **kwargs):
kwargs = {}
elif func is None:
# nicer error message
raise TypeError("Must provide 'func' or tuples of " "'(column, aggfunc).")
raise TypeError("Must provide 'func' or tuples of '(column, aggfunc).")

func = _maybe_mangle_lambdas(func)

Expand Down Expand Up @@ -836,9 +836,7 @@ def aggregate(self, func_or_funcs=None, *args, **kwargs):

relabeling = func_or_funcs is None
columns = None
no_arg_message = (
"Must provide 'func_or_funcs' or named " "aggregation **kwargs."
)
no_arg_message = "Must provide 'func_or_funcs' or named aggregation **kwargs."
if relabeling:
columns = list(kwargs)
if not PY36:
Expand Down
12 changes: 5 additions & 7 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def get_converter(s):
name_sample = names[0]
if isinstance(index_sample, tuple):
if not isinstance(name_sample, tuple):
msg = "must supply a tuple to get_group with multiple" " grouping keys"
msg = "must supply a tuple to get_group with multiple grouping keys"
raise ValueError(msg)
if not len(name_sample) == len(index_sample):
try:
Expand Down Expand Up @@ -715,7 +715,7 @@ def f(g):

else:
raise ValueError(
"func must be a callable if args or " "kwargs are supplied"
"func must be a callable if args or kwargs are supplied"
)
else:
f = func
Expand Down Expand Up @@ -1872,7 +1872,7 @@ def quantile(self, q=0.5, interpolation="linear"):
def pre_processor(vals: np.ndarray) -> Tuple[np.ndarray, Optional[Type]]:
if is_object_dtype(vals):
raise TypeError(
"'quantile' cannot be performed against " "'object' dtypes!"
"'quantile' cannot be performed against 'object' dtypes!"
)

inference = None
Expand Down Expand Up @@ -2201,9 +2201,7 @@ def _get_cythonized_result(
`Series` or `DataFrame` with filled values
"""
if result_is_index and aggregate:
raise ValueError(
"'result_is_index' and 'aggregate' cannot both " "be True!"
)
raise ValueError("'result_is_index' and 'aggregate' cannot both be True!")
if post_processing:
if not callable(pre_processing):
raise ValueError("'post_processing' must be a callable!")
Expand All @@ -2212,7 +2210,7 @@ def _get_cythonized_result(
raise ValueError("'pre_processing' must be a callable!")
if not needs_values:
raise ValueError(
"Cannot use 'pre_processing' without " "specifying 'needs_values'!"
"Cannot use 'pre_processing' without specifying 'needs_values'!"
)

labels, _, ngroups = grouper.group_info
Expand Down
16 changes: 5 additions & 11 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pandas.core.arrays import Categorical, ExtensionArray
import pandas.core.common as com
from pandas.core.frame import DataFrame
from pandas.core.groupby.categorical import recode_for_groupby, recode_from_groupby
from pandas.core.groupby.ops import BaseGrouper
from pandas.core.index import CategoricalIndex, Index, MultiIndex
from pandas.core.series import Series
Expand Down Expand Up @@ -310,8 +311,6 @@ def __init__(
# a passed Categorical
elif is_categorical_dtype(self.grouper):

from pandas.core.groupby.categorical import recode_for_groupby

self.grouper, self.all_grouper = recode_for_groupby(
self.grouper, self.sort, observed
)
Expand Down Expand Up @@ -361,13 +360,10 @@ def __init__(
# Timestamps like
if getattr(self.grouper, "dtype", None) is not None:
if is_datetime64_dtype(self.grouper):
from pandas import to_datetime

self.grouper = to_datetime(self.grouper)
self.grouper = self.grouper.astype("datetime64[ns]")
elif is_timedelta64_dtype(self.grouper):
from pandas import to_timedelta

self.grouper = to_timedelta(self.grouper)
self.grouper = self.grouper.astype("timedelta64[ns]")

def __repr__(self):
return "Grouping({0})".format(self.name)
Expand Down Expand Up @@ -400,8 +396,6 @@ def labels(self):
@cache_readonly
def result_index(self):
if self.all_grouper is not None:
from pandas.core.groupby.categorical import recode_from_groupby

return recode_from_groupby(self.all_grouper, self.sort, self.group_index)
return self.group_index

Expand Down Expand Up @@ -493,12 +487,12 @@ def _get_grouper(
elif nlevels == 0:
raise ValueError("No group keys passed!")
else:
raise ValueError("multiple levels only valid with " "MultiIndex")
raise ValueError("multiple levels only valid with MultiIndex")

if isinstance(level, str):
if obj.index.name != level:
raise ValueError(
"level name {} is not the name of the " "index".format(level)
"level name {} is not the name of the index".format(level)
)
elif level > 0 or level < -1:
raise ValueError("level > 0 or level < -1 only valid with MultiIndex")
Expand Down
14 changes: 5 additions & 9 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
elif is_datetime64_any_dtype(values):
if how in ["add", "prod", "cumsum", "cumprod"]:
raise NotImplementedError(
"datetime64 type does not support {} " "operations".format(how)
"datetime64 type does not support {} operations".format(how)
)
elif is_timedelta64_dtype(values):
if how in ["prod", "cumprod"]:
raise NotImplementedError(
"timedelta64 type does not support {} " "operations".format(how)
"timedelta64 type does not support {} operations".format(how)
)

arity = self._cython_arity.get(how, 1)
Expand All @@ -489,7 +489,7 @@ def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
values = values.T
if arity > 1:
raise NotImplementedError(
"arity of more than 1 is not " "supported for the 'how' argument"
"arity of more than 1 is not supported for the 'how' argument"
)
out_shape = (self.ngroups,) + values.shape[1:]

Expand Down Expand Up @@ -604,9 +604,7 @@ def _aggregate(
):
if values.ndim > 3:
# punting for now
raise NotImplementedError(
"number of dimensions is currently " "limited to 3"
)
raise NotImplementedError("number of dimensions is currently limited to 3")
elif values.ndim > 2:
for i, chunk in enumerate(values.transpose(2, 0, 1)):

Expand All @@ -631,9 +629,7 @@ def _transform(
comp_ids, _, ngroups = self.group_info
if values.ndim > 3:
# punting for now
raise NotImplementedError(
"number of dimensions is currently " "limited to 3"
)
raise NotImplementedError("number of dimensions is currently limited to 3")
elif values.ndim > 2:
for i, chunk in enumerate(values.transpose(2, 0, 1)):

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,4 @@ def __new__(cls, data):
except Exception:
pass # we raise an attribute error anyway

raise AttributeError("Can only use .dt accessor with datetimelike " "values")
raise AttributeError("Can only use .dt accessor with datetimelike values")
32 changes: 12 additions & 20 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ def __new__(
data = maybe_cast_to_integer_array(data, dtype, copy=copy)
elif inferred in ["floating", "mixed-integer-float"]:
if isna(data).any():
raise ValueError(
"cannot convert float " "NaN to integer"
)
raise ValueError("cannot convert float NaN to integer")

if inferred == "mixed-integer-float":
data = maybe_cast_to_integer_array(data, dtype)
Expand Down Expand Up @@ -1182,7 +1180,7 @@ def summary(self, name=None):
.. deprecated:: 0.23.0
"""
warnings.warn(
"'summary' is deprecated and will be removed in a " "future version.",
"'summary' is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -1521,7 +1519,7 @@ def _validate_index_level(self, level):
)
elif level > 0:
raise IndexError(
"Too many levels:" " Index has only 1 level, not %d" % (level + 1)
"Too many levels: Index has only 1 level, not %d" % (level + 1)
)
elif level != self.name:
raise KeyError(
Expand Down Expand Up @@ -2953,7 +2951,7 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):

if not self.is_unique:
raise InvalidIndexError(
"Reindexing only valid with uniquely" " valued Index objects"
"Reindexing only valid with uniquely valued Index objects"
)

if method == "pad" or method == "backfill":
Expand All @@ -2980,7 +2978,7 @@ def _convert_tolerance(self, tolerance, target):
# override this method on subclasses
tolerance = np.asarray(tolerance)
if target.size != tolerance.size and tolerance.size > 1:
raise ValueError("list-like tolerance size must match " "target index size")
raise ValueError("list-like tolerance size must match target index size")
return tolerance

def _get_fill_indexer(self, target, method, limit=None, tolerance=None):
Expand Down Expand Up @@ -3712,9 +3710,7 @@ def _get_leaf_sorter(labels):
return lib.get_level_sorter(lab, ensure_int64(starts))

if isinstance(self, MultiIndex) and isinstance(other, MultiIndex):
raise TypeError(
"Join on level between two MultiIndex objects " "is ambiguous"
)
raise TypeError("Join on level between two MultiIndex objects is ambiguous")

left, right = self, other

Expand All @@ -3728,7 +3724,7 @@ def _get_leaf_sorter(labels):

if not right.is_unique:
raise NotImplementedError(
"Index._join_level on non-unique index " "is not implemented"
"Index._join_level on non-unique index is not implemented"
)

new_level, left_lev_indexer, right_lev_indexer = old_level.join(
Expand Down Expand Up @@ -4554,9 +4550,7 @@ def sort(self, *args, **kwargs):
"""
Use sort_values instead.
"""
raise TypeError(
"cannot sort an Index object in-place, use " "sort_values instead"
)
raise TypeError("cannot sort an Index object in-place, use sort_values instead")

def shift(self, periods=1, freq=None):
"""
Expand Down Expand Up @@ -5205,7 +5199,7 @@ def slice_locs(self, start=None, end=None, step=None, kind=None):
pass
else:
if not tz_compare(ts_start.tzinfo, ts_end.tzinfo):
raise ValueError("Both dates must have the " "same UTC offset")
raise ValueError("Both dates must have the same UTC offset")

start_slice = None
if start is not None:
Expand Down Expand Up @@ -5397,12 +5391,10 @@ def _validate_for_numeric_binop(self, other, op):

if isinstance(other, (Index, ABCSeries, np.ndarray)):
if len(self) != len(other):
raise ValueError("cannot evaluate a numeric op with " "unequal lengths")
raise ValueError("cannot evaluate a numeric op with unequal lengths")
other = com.values_from_object(other)
if other.dtype.kind not in ["f", "i", "u"]:
raise TypeError(
"cannot evaluate a numeric op " "with a non-numeric dtype"
)
raise TypeError("cannot evaluate a numeric op with a non-numeric dtype")
elif isinstance(other, (ABCDateOffset, np.timedelta64, timedelta)):
# higher up to handle
pass
Expand Down Expand Up @@ -5571,7 +5563,7 @@ def logical_func(self, *args, **kwargs):
return logical_func

cls.all = _make_logical_function(
"all", "Return whether all elements " "are True.", np.all
"all", "Return whether all elements are True.", np.all
)
cls.any = _make_logical_function(
"any", "Return whether any element is True.", np.any
Expand Down
Loading