Skip to content

CLN: Prune unnecessary internals #27685

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
Aug 1, 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
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def _transform_item_by_item(self, obj, wrapper):
except Exception:
pass

if len(output) == 0: # pragma: no cover
if len(output) == 0:
raise TypeError("Transform function invalid for data types")

columns = obj.columns
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ def mean(self, *args, **kwargs):
)
except GroupByError:
raise
except Exception: # pragma: no cover
except Exception:
with _group_selection_context(self):
f = lambda x: x.mean(axis=self.axis, **kwargs)
return self._python_agg_general(f)
Expand All @@ -1232,7 +1232,7 @@ def median(self, **kwargs):
)
except GroupByError:
raise
except Exception: # pragma: no cover
except Exception:

def f(x):
if isinstance(x, np.ndarray):
Expand Down Expand Up @@ -2470,7 +2470,7 @@ def groupby(obj, by, **kwds):
from pandas.core.groupby.generic import DataFrameGroupBy

klass = DataFrameGroupBy
else: # pragma: no cover
else:
raise TypeError("invalid type: {}".format(obj))

return klass(obj, by, **kwds)
8 changes: 3 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def to_native_types(self, slicer=None, na_rep="nan", quoting=None, **kwargs):
values[mask] = na_rep
return values

# block actions ####
# block actions #
def copy(self, deep=True):
""" copy constructor """
values = self.values
Expand Down Expand Up @@ -1538,16 +1538,14 @@ def quantile(self, qs, interpolation="linear", axis=0):
).reshape(len(values), len(qs))
else:
# asarray needed for Sparse, see GH#24600
# Note: we use self.values below instead of values because the
# `asi8` conversion above will behave differently under `isna`
mask = np.asarray(isna(self.values))
mask = np.asarray(isna(values))
result = nanpercentile(
values,
np.array(qs) * 100,
axis=axis,
na_value=self.fill_value,
mask=mask,
ndim=self.ndim,
ndim=values.ndim,
interpolation=interpolation,
)

Expand Down
2 changes: 0 additions & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,6 @@ def iget(self, i):
"""
block = self.blocks[self._blknos[i]]
values = block.iget(self._blklocs[i])
if values.ndim != 1:
return values

# shortcut for select a single-dim from a 2-dim BM
return SingleBlockManager(
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/clipboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def to_clipboard(obj, excel=True, sep=None, **kwargs): # pragma: no cover
return
except TypeError:
warnings.warn(
"to_clipboard in excel mode requires a single " "character separator."
"to_clipboard in excel mode requires a single character separator."
)
elif sep is not None:
warnings.warn("to_clipboard with excel=False ignores the sep argument")
Expand Down
10 changes: 4 additions & 6 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def read_excel(
for arg in ("sheet", "sheetname", "parse_cols"):
if arg in kwds:
raise TypeError(
"read_excel() got an unexpected keyword argument " "`{}`".format(arg)
"read_excel() got an unexpected keyword argument `{}`".format(arg)
)

if not isinstance(io, ExcelFile):
Expand Down Expand Up @@ -353,7 +353,7 @@ def __init__(self, filepath_or_buffer):
self.book = self.load_workbook(filepath_or_buffer)
else:
raise ValueError(
"Must explicitly set engine if not passing in" " buffer or path for io."
"Must explicitly set engine if not passing in buffer or path for io."
)

@property
Expand Down Expand Up @@ -713,9 +713,7 @@ def _get_sheet_name(self, sheet_name):
if sheet_name is None:
sheet_name = self.cur_sheet
if sheet_name is None: # pragma: no cover
raise ValueError(
"Must pass explicit sheet_name or set " "cur_sheet property"
)
raise ValueError("Must pass explicit sheet_name or set cur_sheet property")
return sheet_name

def _value_with_fmt(self, val):
Expand Down Expand Up @@ -851,7 +849,7 @@ def parse(
"""
if "chunksize" in kwds:
raise NotImplementedError(
"chunksize keyword of read_excel " "is not implemented"
"chunksize keyword of read_excel is not implemented"
)

return self._reader.parse(
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/feather_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def to_feather(df, path):

if df.index.name is not None:
raise ValueError(
"feather does not serialize index meta-data on a " "default index"
"feather does not serialize index meta-data on a default index"
)

# validate columns
Expand Down
6 changes: 2 additions & 4 deletions pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def __init__(
# validate mi options
if self.has_mi_columns:
if cols is not None:
raise TypeError(
"cannot specify cols with a MultiIndex on the " "columns"
)
raise TypeError("cannot specify cols with a MultiIndex on the columns")

if cols is not None:
if isinstance(cols, ABCIndexClass):
Expand Down Expand Up @@ -158,7 +156,7 @@ def save(self):
"""
# GH21227 internal compression is not used when file-like passed.
if self.compression and hasattr(self.path_or_buf, "write"):
msg = "compression has no effect when passing file-like " "object as input."
msg = "compression has no effect when passing file-like object as input."
warnings.warn(msg, RuntimeWarning, stacklevel=2)

# when zip compression is called.
Expand Down
10 changes: 4 additions & 6 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Internal module for formatting output data in csv, html,
and latex files. This module also applies to display formatting.
"""

import decimal
from functools import partial
from io import StringIO
import math
import re
from shutil import get_terminal_size
from typing import (
Expand Down Expand Up @@ -862,7 +863,7 @@ def to_latex(
with codecs.open(self.buf, "w", encoding=encoding) as f:
latex_renderer.write_result(f)
else:
raise TypeError("buf is not a file name and it has no write " "method")
raise TypeError("buf is not a file name and it has no write method")

def _format_col(self, i: int) -> List[str]:
frame = self.tr_frame
Expand Down Expand Up @@ -907,7 +908,7 @@ def to_html(
with open(self.buf, "w") as f:
buffer_put_lines(f, html)
else:
raise TypeError("buf is not a file name and it has no write " " method")
raise TypeError("buf is not a file name and it has no write method")

def _get_formatted_column_labels(self, frame: "DataFrame") -> List[List[str]]:
from pandas.core.index import _sparsify
Expand Down Expand Up @@ -1782,9 +1783,6 @@ def __call__(self, num: Union[int, float]) -> str:

@return: engineering formatted string
"""
import decimal
import math

dnum = decimal.Decimal(str(num))

if decimal.Decimal.is_nan(dnum):
Expand Down
24 changes: 11 additions & 13 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def parser_f(
read_csv = Appender(
_doc_read_csv_and_table.format(
func_name="read_csv",
summary=("Read a comma-separated values (csv) file " "into DataFrame."),
summary=("Read a comma-separated values (csv) file into DataFrame."),
_default_sep="','",
)
)(read_csv)
Expand Down Expand Up @@ -770,7 +770,7 @@ def read_fwf(
if colspecs is None and widths is None:
raise ValueError("Must specify either colspecs or widths")
elif colspecs not in (None, "infer") and widths is not None:
raise ValueError("You must specify only one of 'widths' and " "'colspecs'")
raise ValueError("You must specify only one of 'widths' and 'colspecs'")

# Compute 'colspecs' from 'widths', if specified.
if widths is not None:
Expand Down Expand Up @@ -901,9 +901,7 @@ def _get_options_with_defaults(self, engine):

# see gh-12935
if argname == "mangle_dupe_cols" and not value:
raise ValueError(
"Setting mangle_dupe_cols=False is " "not supported yet"
)
raise ValueError("Setting mangle_dupe_cols=False is not supported yet")
else:
options[argname] = value

Expand Down Expand Up @@ -942,7 +940,7 @@ def _check_file_or_buffer(self, f, engine):
# needs to have that attribute ("next" for Python 2.x, "__next__"
# for Python 3.x)
if engine != "c" and not hasattr(f, next_attr):
msg = "The 'python' engine cannot iterate " "through this file buffer."
msg = "The 'python' engine cannot iterate through this file buffer."
raise ValueError(msg)

return engine
Expand All @@ -959,7 +957,7 @@ def _clean_options(self, options, engine):
# C engine not supported yet
if engine == "c":
if options["skipfooter"] > 0:
fallback_reason = "the 'c' engine does not support" " skipfooter"
fallback_reason = "the 'c' engine does not support skipfooter"
engine = "python"

encoding = sys.getfilesystemencoding() or "utf-8"
Expand Down Expand Up @@ -1397,11 +1395,11 @@ def __init__(self, kwds):
raise ValueError("header must be integer or list of integers")
if kwds.get("usecols"):
raise ValueError(
"cannot specify usecols when " "specifying a multi-index header"
"cannot specify usecols when specifying a multi-index header"
)
if kwds.get("names"):
raise ValueError(
"cannot specify names when " "specifying a multi-index header"
"cannot specify names when specifying a multi-index header"
)

# validate index_col that only contains integers
Expand Down Expand Up @@ -1611,7 +1609,7 @@ def _get_name(icol):

if col_names is None:
raise ValueError(
("Must supply column order to use {icol!s} " "as index").format(
("Must supply column order to use {icol!s} as index").format(
icol=icol
)
)
Expand Down Expand Up @@ -2379,7 +2377,7 @@ def _make_reader(self, f):
if sep is None or len(sep) == 1:
if self.lineterminator:
raise ValueError(
"Custom line terminators not supported in " "python parser (yet)"
"Custom line terminators not supported in python parser (yet)"
)

class MyDialect(csv.Dialect):
Expand Down Expand Up @@ -2662,7 +2660,7 @@ def _infer_columns(self):
"number of header fields in the file"
)
if len(columns) > 1:
raise TypeError("Cannot pass names with multi-index " "columns")
raise TypeError("Cannot pass names with multi-index columns")

if self.usecols is not None:
# Set _use_cols. We don't store columns because they are
Expand Down Expand Up @@ -2727,7 +2725,7 @@ def _handle_usecols(self, columns, usecols_key):
elif any(isinstance(u, str) for u in self.usecols):
if len(columns) > 1:
raise ValueError(
"If using multiple headers, usecols must " "be integers."
"If using multiple headers, usecols must be integers."
)
col_indices = []

Expand Down
20 changes: 9 additions & 11 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def read_hdf(path_or_buf, key=None, mode="r", **kwargs):
path_or_buf = _stringify_path(path_or_buf)
if not isinstance(path_or_buf, str):
raise NotImplementedError(
"Support for generic buffers has not " "been implemented."
"Support for generic buffers has not been implemented."
)
try:
exists = os.path.exists(path_or_buf)
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def append(
"""
if columns is not None:
raise TypeError(
"columns is not a supported keyword in append, " "try data_columns"
"columns is not a supported keyword in append, try data_columns"
)

if dropna is None:
Expand Down Expand Up @@ -2161,7 +2161,7 @@ def set_atom(
# which is an error

raise TypeError(
"too many timezones in this block, create separate " "data columns"
"too many timezones in this block, create separate data columns"
)
elif inferred_type == "unicode":
raise TypeError("[unicode] is not implemented as a table column")
Expand Down Expand Up @@ -2338,9 +2338,7 @@ def validate_attr(self, append):
if append:
existing_fields = getattr(self.attrs, self.kind_attr, None)
if existing_fields is not None and existing_fields != list(self.values):
raise ValueError(
"appended items do not match existing items" " in table!"
)
raise ValueError("appended items do not match existing items in table!")

existing_dtype = getattr(self.attrs, self.dtype_attr, None)
if existing_dtype is not None and existing_dtype != self.dtype:
Expand Down Expand Up @@ -2834,7 +2832,7 @@ def write_multi_index(self, key, index):
# write the level
if is_extension_type(lev):
raise NotImplementedError(
"Saving a MultiIndex with an " "extension dtype is not supported."
"Saving a MultiIndex with an extension dtype is not supported."
)
level_key = "{key}_level{idx}".format(key=key, idx=i)
conv_level = _convert_index(
Expand Down Expand Up @@ -3079,7 +3077,7 @@ def validate_read(self, kwargs):
kwargs = super().validate_read(kwargs)
if "start" in kwargs or "stop" in kwargs:
raise NotImplementedError(
"start and/or stop are not supported " "in fixed Sparse reading"
"start and/or stop are not supported in fixed Sparse reading"
)
return kwargs

Expand Down Expand Up @@ -3376,7 +3374,7 @@ def validate_multiindex(self, obj):
return obj.reset_index(), levels
except ValueError:
raise ValueError(
"duplicate names/columns in the multi-index when " "storing as a table"
"duplicate names/columns in the multi-index when storing as a table"
)

@property
Expand Down Expand Up @@ -4081,7 +4079,7 @@ def read_column(self, column, where=None, start=None, stop=None):
return False

if where is not None:
raise TypeError("read_column does not currently accept a where " "clause")
raise TypeError("read_column does not currently accept a where clause")

# find the axes
for a in self.axes:
Expand Down Expand Up @@ -4990,7 +4988,7 @@ def __init__(self, table, where=None, start=None, stop=None):
self.stop is not None and (where >= self.stop).any()
):
raise ValueError(
"where must have index locations >= start and " "< stop"
"where must have index locations >= start and < stop"
)
self.coordinates = where

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/sas/sas_xport.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"000000000000000000000000000000 "
)
_correct_header1 = (
"HEADER RECORD*******MEMBER HEADER RECORD!!!!!!!" "000000000000000001600000000"
"HEADER RECORD*******MEMBER HEADER RECORD!!!!!!!000000000000000001600000000"
)
_correct_header2 = (
"HEADER RECORD*******DSCRPTR HEADER RECORD!!!!!!!"
Expand Down
Loading