Skip to content

STYLE: enable pylint warnings for cell-var-from-loop #49445

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 21 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a9793f5
STYLE: Refactored one loop, suppressed three false positives.
Nov 1, 2022
eee0510
Merge branch 'pandas-dev:main' into cell_var_from_loop
roadswitcher Nov 1, 2022
724f3c7
Oooh, didn't think of that.
roadswitcher Nov 1, 2022
98b6991
I need to get better at spotting this stuff.
roadswitcher Nov 1, 2022
412391e
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 1, 2022
d4b22e5
Yeah, let's not suppress those after all.
roadswitcher Nov 1, 2022
eb3bdd6
Merge branch 'cell_var_from_loop' of github.com:roadswitcher/pandas i…
roadswitcher Nov 1, 2022
e672d53
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 1, 2022
08baba9
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 1, 2022
7572c87
Accidentally removed a newline.
roadswitcher Nov 1, 2022
4ec8eaa
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 1, 2022
eb74060
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 2, 2022
2a681f9
Helps to revert to correct version of file.
roadswitcher Nov 2, 2022
d4c8674
OK, backing slowly away from the git client now.
roadswitcher Nov 2, 2022
a1f410f
OK, backing slowly away from the git client now.
roadswitcher Nov 2, 2022
7f9de43
Resolve autotyper find
roadswitcher Nov 2, 2022
9b360fa
Added type hints per reviewer note.
roadswitcher Nov 2, 2022
e5b8d7a
Update pandas/core/strings/object_array.py
roadswitcher Nov 2, 2022
fa3c521
Update pandas/tests/io/parser/test_c_parser_only.py
roadswitcher Nov 2, 2022
f486673
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 2, 2022
564a4b2
Merge branch 'main' into cell_var_from_loop
roadswitcher Nov 3, 2022
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
8 changes: 7 additions & 1 deletion pandas/core/strings/object_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from collections.abc import Callable # noqa: PDF001
import functools
import re
import textwrap
from typing import (
Expand Down Expand Up @@ -380,9 +381,14 @@ def _str_get_dummies(self, sep: str = "|"):

dummies = np.empty((len(arr), len(tags2)), dtype=np.int64)

def _isin(test_elements: str, element: str) -> bool:
return element in test_elements

for i, t in enumerate(tags2):
pat = sep + t + sep
dummies[:, i] = lib.map_infer(arr.to_numpy(), lambda x: pat in x)
dummies[:, i] = lib.map_infer(
arr.to_numpy(), functools.partial(_isin, element=pat)
)
return dummies, tags2

def _str_upper(self):
Expand Down
56 changes: 28 additions & 28 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4106,44 +4106,44 @@ def process_axes(self, obj, selection: Selection, columns=None) -> DataFrame:
for axis, labels in self.non_index_axes:
obj = _reindex_axis(obj, axis, labels, columns)

# apply the selection filters (but keep in the same order)
if selection.filter is not None:
for field, op, filt in selection.filter.format():
def process_filter(field, filt, op):

def process_filter(field, filt):
for axis_name in obj._AXIS_ORDERS:
axis_number = obj._get_axis_number(axis_name)
axis_values = obj._get_axis(axis_name)
assert axis_number is not None

for axis_name in obj._AXIS_ORDERS:
axis_number = obj._get_axis_number(axis_name)
axis_values = obj._get_axis(axis_name)
assert axis_number is not None
# see if the field is the name of an axis
if field == axis_name:

# see if the field is the name of an axis
if field == axis_name:
# if we have a multi-index, then need to include
# the levels
if self.is_multi_index:
filt = filt.union(Index(self.levels))

# if we have a multi-index, then need to include
# the levels
if self.is_multi_index:
filt = filt.union(Index(self.levels))
takers = op(axis_values, filt)
return obj.loc(axis=axis_number)[takers]

takers = op(axis_values, filt)
return obj.loc(axis=axis_number)[takers]
# this might be the name of a file IN an axis
elif field in axis_values:

# this might be the name of a file IN an axis
elif field in axis_values:
# we need to filter on this dimension
values = ensure_index(getattr(obj, field).values)
filt = ensure_index(filt)

# we need to filter on this dimension
values = ensure_index(getattr(obj, field).values)
filt = ensure_index(filt)
# hack until we support reversed dim flags
if isinstance(obj, DataFrame):
axis_number = 1 - axis_number

# hack until we support reversed dim flags
if isinstance(obj, DataFrame):
axis_number = 1 - axis_number
takers = op(values, filt)
return obj.loc(axis=axis_number)[takers]
takers = op(values, filt)
return obj.loc(axis=axis_number)[takers]

raise ValueError(f"cannot find the field [{field}] for filtering!")
raise ValueError(f"cannot find the field [{field}] for filtering!")

obj = process_filter(field, filt)
# apply the selection filters (but keep in the same order)
if selection.filter is not None:
for field, op, filt in selection.filter.format():
obj = process_filter(field, filt, op)

return obj

Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/parser/test_c_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def test_precise_conversion(c_parser_only):
normal_errors = []
precise_errors = []

def error(val: float, actual_val: Decimal) -> Decimal:
return abs(Decimal(f"{val:.100}") - actual_val)

# test numbers between 1 and 2
for num in np.linspace(1.0, 2.0, num=500):
# 25 decimal digits of precision
Expand All @@ -192,11 +195,8 @@ def test_precise_conversion(c_parser_only):
)
actual_val = Decimal(text[2:])

def error(val):
return abs(Decimal(f"{val:.100}") - actual_val)

normal_errors.append(error(normal_val))
precise_errors.append(error(precise_val))
normal_errors.append(error(normal_val, actual_val))
precise_errors.append(error(precise_val, actual_val))

# round-trip should match float()
assert roundtrip_val == float(text[2:])
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ disable = [
"arguments-renamed",
"attribute-defined-outside-init",
"broad-except",
"cell-var-from-loop",
"comparison-with-callable",
"confusing-with-statement",
"dangerous-default-value",
Expand Down