Skip to content

CLN refactor non-core #37580

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
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 3 additions & 7 deletions pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class option_context(ContextDecorator):
"""

def __init__(self, *args):
if not (len(args) % 2 == 0 and len(args) >= 2):
if len(args) % 2 != 0 or len(args) < 2:
raise ValueError(
"Need to invoke as option_context(pat, val, [(pat, val), ...])."
)
Expand Down Expand Up @@ -648,7 +648,7 @@ def _build_option_description(k: str) -> str:
s += f"\n [default: {o.defval}] [currently: {_get_option(k, True)}]"

if d:
rkey = d.rkey if d.rkey else ""
rkey = d.rkey or ""
s += "\n (Deprecated"
s += f", use `{rkey}` instead."
s += ")"
Expand Down Expand Up @@ -827,13 +827,9 @@ def is_nonnegative_int(value: Optional[int]) -> None:
ValueError
When the value is not None or is a negative integer
"""
if value is None:
if isinstance(value, int) and value >= 0 or value is None:
Copy link
Member

Choose a reason for hiding this comment

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

i find the status quo slightly clearer, also nice to be able to see in codecov which conditions are reached

return

elif isinstance(value, int):
if value >= 0:
return

msg = "Value must be a nonnegative integer or None"
raise ValueError(msg)

Expand Down
3 changes: 1 addition & 2 deletions pandas/_config/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def _valid_locales(locales, normalize):


def _default_locale_getter():
raw_locales = subprocess.check_output(["locale -a"], shell=True)
return raw_locales
return subprocess.check_output(["locale -a"], shell=True)


def get_locales(prefix=None, normalize=True, locale_getter=_default_locale_getter):
Expand Down
18 changes: 9 additions & 9 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,7 @@ def _get_ilevel_values(index, level):
unique = index.levels[level]
level_codes = index.codes[level]
filled = take_1d(unique._values, level_codes, fill_value=unique._na_value)
values = unique._shallow_copy(filled, name=index.names[level])
return values
return unique._shallow_copy(filled, name=index.names[level])

if check_less_precise is not no_default:
warnings.warn(
Expand Down Expand Up @@ -1871,8 +1870,7 @@ def makeTimedeltaIndex(k=10, freq="D", name=None, **kwargs):

def makePeriodIndex(k=10, name=None, **kwargs):
dt = datetime(2000, 1, 1)
dr = pd.period_range(start=dt, periods=k, freq="B", name=name, **kwargs)
return dr
return pd.period_range(start=dt, periods=k, freq="B", name=name, **kwargs)


def makeMultiIndex(k=10, names=None, **kwargs):
Expand Down Expand Up @@ -2511,9 +2509,12 @@ def network(

@wraps(t)
def wrapper(*args, **kwargs):
if check_before_test and not raise_on_error:
if not can_connect(url, error_classes):
skip()
if (
check_before_test
and not raise_on_error
and not can_connect(url, error_classes)
):
skip()
try:
return t(*args, **kwargs)
except Exception as err:
Expand Down Expand Up @@ -2928,8 +2929,7 @@ def convert_rows_list_to_csv_str(rows_list: List[str]):
Expected output of to_csv() in current OS.
"""
sep = os.linesep
expected = sep.join(rows_list) + sep
return expected
return sep.join(rows_list) + sep


def external_error_raised(expected_exception: Type[Exception]) -> ContextManager:
Expand Down
36 changes: 15 additions & 21 deletions pandas/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def get_keywords():
# get_keywords().
git_refnames = "$Format:%d$"
git_full = "$Format:%H$"
keywords = {"refnames": git_refnames, "full": git_full}
return keywords
return {"refnames": git_refnames, "full": git_full}


class VersioneerConfig:
Expand Down Expand Up @@ -121,17 +120,16 @@ def git_get_keywords(versionfile_abs):
# _version.py.
keywords = {}
try:
f = open(versionfile_abs)
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["refnames"] = mo.group(1)
if line.strip().startswith("git_full ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["full"] = mo.group(1)
f.close()
with open(versionfile_abs) as f:
Copy link
Member

Choose a reason for hiding this comment

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

as long as you're doing this, can "f" become "fd"

for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["refnames"] = mo.group(1)
if line.strip().startswith("git_full ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["full"] = mo.group(1)
except OSError:
pass
return keywords
Expand Down Expand Up @@ -286,13 +284,11 @@ def render_pep440(pieces):
if pieces["distance"] or pieces["dirty"]:
rendered += plus_or_dot(pieces)
rendered += f"{pieces['distance']:d}.g{pieces['short']}"
if pieces["dirty"]:
rendered += ".dirty"
else:
# exception #1
rendered = f"0+untagged.{pieces['distance']:d}.g{pieces['short']}"
if pieces["dirty"]:
rendered += ".dirty"
if pieces["dirty"]:
rendered += ".dirty"
return rendered


Expand Down Expand Up @@ -348,13 +344,11 @@ def render_pep440_old(pieces):
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += f".post{pieces['distance']:d}"
if pieces["dirty"]:
rendered += ".dev0"
else:
# exception #1
rendered = f"0.post{pieces['distance']:d}"
if pieces["dirty"]:
rendered += ".dev0"
if pieces["dirty"]:
rendered += ".dev0"
return rendered


Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def is_platform_windows() -> bool:
bool
True if the running platform is windows.
"""
return sys.platform == "win32" or sys.platform == "cygwin"
return sys.platform in ["win32", "cygwin"]


def is_platform_linux() -> bool:
Expand Down
3 changes: 1 addition & 2 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,12 @@ def _create_multiindex():
major_codes = np.array([0, 0, 1, 2, 3, 3])
minor_codes = np.array([0, 1, 0, 1, 0, 1])
index_names = ["first", "second"]
mi = MultiIndex(
return MultiIndex(
levels=[major_axis, minor_axis],
codes=[major_codes, minor_codes],
names=index_names,
verify_integrity=False,
)
return mi


def _create_mi_with_dt64tz_level():
Expand Down