Skip to content

CLN: various lgtm.com cleanups #30258

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
Dec 15, 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
1 change: 0 additions & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ def apply_series_generator(self) -> Tuple[ResType, "Index"]:
series_gen = self.series_generator
res_index = self.result_index

i = None
keys = []
results = {}
if self.ignore_failures:
Expand Down
1 change: 0 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,6 @@ def _validate_dt64_dtype(dtype):
dtype = pandas_dtype(dtype)
if is_dtype_equal(dtype, np.dtype("M8")):
# no precision, disallowed GH#24806
dtype = _NS_DTYPE
msg = (
"Passing in 'datetime64' dtype with no precision is not allowed. "
"Please pass in 'datetime64[ns]' instead."
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def itemsize(self):

@classmethod
def construct_array_type(cls):
"""Return the array type associated with this dtype
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this docstring not inherited from the base class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not as far as I'm aware. Should it be?

Copy link
Member Author

@simonjayhawkins simonjayhawkins Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like inspect.getdoc(object) https://docs.python.org/3/library/inspect.html?highlight=inspect#inspect.getdoc could get the baseclass docstring.

I'm using VSCode and not showing baseclass docstring when no docstring exists on derived class.

_IntegerDtype().construct_array_type.__doc__ returns None if no docstring exists on derived class but help(_IntegerDtype().construct_array_type) does show the inherited doctstring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok this is odd then I agree with @TomAugspurger that these should inherit the baseclass, odd that they are not.

Return the array type associated with this dtype.

Returns
-------
Expand Down
8 changes: 8 additions & 0 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ def construct_from_string(cls, string):
f"Cannot construct a 'PandasDtype' from '{string}'"
) from err

@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype.

Returns
-------
type
"""
return PandasArray

@property
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/arrays/sparse/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ def __repr__(self) -> str:

@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype.

Returns
-------
type
"""
from .array import SparseArray

return SparseArray
Expand Down
1 change: 0 additions & 1 deletion pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ def _validate_td64_dtype(dtype):
dtype = pandas_dtype(dtype)
if is_dtype_equal(dtype, np.dtype("timedelta64")):
# no precision disallowed GH#24806
dtype = _TD_DTYPE
msg = (
"Passing in 'timedelta' dtype with no precision is not allowed. "
"Please pass in 'timedelta64[ns]' instead."
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def names(self) -> Optional[List[str]]:
@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype
Return the array type associated with this dtype.

Returns
-------
Expand Down
15 changes: 11 additions & 4 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype
Return the array type associated with this dtype.

Returns
-------
Expand Down Expand Up @@ -668,7 +668,7 @@ def __init__(self, unit="ns", tz=None):
unit = result.unit
tz = result.tz
msg = (
"Passing a dtype alias like 'datetime64[ns, {tz}]' "
f"Passing a dtype alias like 'datetime64[ns, {tz}]' "
"to DatetimeTZDtype is no longer supported. Use "
"'DatetimeTZDtype.construct_from_string()' instead."
)
Expand Down Expand Up @@ -704,7 +704,7 @@ def tz(self):
@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype
Return the array type associated with this dtype.

Returns
-------
Expand Down Expand Up @@ -936,6 +936,13 @@ def is_dtype(cls, dtype) -> bool:

@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype.

Returns
-------
type
"""
from pandas.core.arrays import PeriodArray

return PeriodArray
Expand Down Expand Up @@ -1030,7 +1037,7 @@ def subtype(self):
@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype
Return the array type associated with this dtype.

Returns
-------
Expand Down
1 change: 0 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,6 @@ def _ixs(self, i: int, axis: int = 0):
"""
# irow
if axis == 0:
label = self.index[i]
new_values = self._data.fast_xs(i)

# if we are a copy, mark as such
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5746,8 +5746,6 @@ def __deepcopy__(self: FrameOrSeries, memo=None) -> FrameOrSeries:
memo, default None
Standard signature. Unused
"""
if memo is None:
memo = {}
return self.copy(deep=True)

def _convert(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _get_grouper(self, obj, validate: bool = True):
"""

self._set_grouper(obj)
self.grouper, exclusions, self.obj = get_grouper(
self.grouper, _, self.obj = get_grouper(
self.obj,
[self.key],
axis=self.axis,
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,6 @@ def __deepcopy__(self, memo=None):
memo, default None
Standard signature. Unused
"""
if memo is None:
memo = {}
return self.copy(deep=True)

# --------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3024,7 +3024,6 @@ def _merge_blocks(blocks, dtype=None, _can_consolidate=True):
if dtype is None:
if len({b.dtype for b in blocks}) != 1:
raise AssertionError("_merge_blocks are invalid!")
dtype = blocks[0].dtype

# FIXME: optimization potential in case all mgrs contain slices and
# combination of those slices is a slice, too.
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,9 @@ def get_new_values(self):
if needs_i8_conversion(values):
sorted_values = sorted_values.view("i8")
new_values = new_values.view("i8")
name = "int64"
elif is_bool_dtype(values):
sorted_values = sorted_values.astype("object")
new_values = new_values.astype("object")
name = "object"
else:
sorted_values = sorted_values.astype(name, copy=False)

Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _args_adjust(self):
values = np.ravel(values)
values = values[~isna(values)]

hist, self.bins = np.histogram(
_, self.bins = np.histogram(
values,
bins=self.bins,
range=self.kwds.get("range", None),
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ class DecimalDtype2(DecimalDtype):

@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype.

Returns
-------
type
"""
return DecimalArray2


Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/extension/arrow/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def construct_from_string(cls, string):

@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype.

Returns
-------
type
"""
return ArrowBoolArray

def _is_boolean(self):
Expand All @@ -60,6 +67,13 @@ def construct_from_string(cls, string):

@classmethod
def construct_array_type(cls):
"""
Return the array type associated with this dtype.

Returns
-------
type
"""
return ArrowStringArray


Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __repr__(self) -> str:

@classmethod
def construct_array_type(cls):
"""Return the array type associated with this dtype
"""
Return the array type associated with this dtype.

Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class JSONDtype(ExtensionDtype):

@classmethod
def construct_array_type(cls):
"""Return the array type associated with this dtype
"""
Return the array type associated with this dtype.

Returns
-------
Expand Down