Skip to content

CLN refactor rest of core #37586

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 38 commits into from
Jan 20, 2021
Merged

Conversation

MarcoGorelli
Copy link
Member

Some refactorings found by Sourcery https://sourcery.ai/

I've removed the ones of the kind

- if param:
-     var = a
- else:
-     var = b
+ var = a if param else b

@jreback jreback added the Code Style Code style, linting, code_checks label Nov 2, 2020
@jreback jreback added this to the 1.2 milestone Nov 2, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

one comment otherwise lgtm

else:
object.__setattr__(self, name, value)
self[name] = value
Copy link
Contributor

Choose a reason for hiding this comment

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

can you check the logic that was changed here (IIRC this is for performance but the change might be good)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about this change on L5509. pls revert and can do in a separate PR when checking perf. This causes recursion (which might be fine, though need to confirm)

is_object_dtype(dtype)
or not is_object_dtype(dtype)
and is_object_dtype(values)
and dtype 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.

can you put parens where appropriate to make this more obvious

@@ -1244,8 +1242,7 @@ def searchsorted(self, value, side="left", sorter=None) -> np.ndarray:

def drop_duplicates(self, keep="first"):
duplicated = self.duplicated(keep=keep)
result = self[np.logical_not(duplicated)]
return result
return self[np.logical_not(duplicated)]
Copy link
Member

Choose a reason for hiding this comment

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

id prefer ~duplicated over logical_not

left = left.copy()
right = right.copy()
left.index = join_index
right.index = join_index
Copy link
Member

Choose a reason for hiding this comment

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

identical(?) to chunk above, could make a helper. also im pretty sure mypy is going to complain about Index not having a tz attribute

Copy link
Member Author

Choose a reason for hiding this comment

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

@jbrockmendel do you know when this code is meant to be reached? Running

pytest pandas/tests/generic/

doesn't cover it. I couldn't get here with test_fast.sh either, even though codecov shows it as covered

Copy link
Member

Choose a reason for hiding this comment

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

Looks like test_alignment_doesnt_change_tz from #36503 hits the other usage of this pattern, might not have gotten both

@@ -185,14 +182,11 @@ def _get_fill_value(
else:
return -np.inf
else:
if fill_value_typ is None:
return iNaT
if fill_value_typ is not None and fill_value_typ == "+inf":
Copy link
Member

Choose a reason for hiding this comment

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

i think can just do the str comparison?

if values.ndim == 1:
return fill_value
elif axis is None:
if values.ndim == 1 or axis 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 think this is a case where its useful to see we get coverage of both cases

@@ -218,7 +218,7 @@ def decons_group_index(comp_labels, shape):
x = comp_labels
for i in reversed(range(len(shape))):
labels = (x - y) % (factor * shape[i]) // factor
np.putmask(labels, comp_labels < 0, -1)
np.putmask(labels, x < 0, -1)
Copy link
Member

Choose a reason for hiding this comment

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

lets just do labels[x < 0] = -1, putmask has different semantics when the last arg is a listlike but thats not relevant here

@jreback
Copy link
Contributor

jreback commented Nov 18, 2020

can you merge master ping on green

@MarcoGorelli
Copy link
Member Author

I still need to address #37586 (comment) , will ping when it's ready

@MarcoGorelli MarcoGorelli marked this pull request as draft November 18, 2020 15:14
@jreback jreback removed this from the 1.2 milestone Nov 24, 2020
@jreback
Copy link
Contributor

jreback commented Nov 24, 2020

moving off 1.2 until fixed up

@MarcoGorelli MarcoGorelli marked this pull request as ready for review November 24, 2020 13:55
@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Nov 24, 2020

Sure, no problem, though I believe I've responded to the review comments, I think it should be ready now

@jreback
Copy link
Contributor

jreback commented Dec 22, 2020

@MarcoGorelli can you rebase and see if you can get passing

@jreback jreback added this to the 1.3 milestone Dec 22, 2020
@jreback
Copy link
Contributor

jreback commented Dec 22, 2020

ok this looks fine, but a ci /checks is failing. ping on greenish

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

comment + merge master. master is moving, so ping on green when ready.

@@ -114,11 +114,8 @@ def _ensure_data(
values = extract_array(values, extract_numpy=True)

# we check some simple dtypes first
if is_object_dtype(dtype):
if is_object_dtype(dtype) or (is_object_dtype(values) and (dtype is None)):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove the parens around dtype is None as confusing (and actually put around the entire expression and format)

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

2 changes to revert. these types of PRs are very hard to review. in the future pls split out the non-controversial changes otherwise these linger forever.

ping on green when reverted

else:
object.__setattr__(self, name, value)
self[name] = value
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about this change on L5509. pls revert and can do in a separate PR when checking perf. This causes recursion (which might be fine, though need to confirm)

@@ -11106,6 +11091,22 @@ def last_valid_index(self):
return self._find_valid_index("last")


def _set_join_index(
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not be here but in pandas/core/reshape/merge.py or appropriate

@MarcoGorelli MarcoGorelli marked this pull request as draft January 18, 2021 13:17
@MarcoGorelli MarcoGorelli mentioned this pull request Jan 18, 2021
1 task
@MarcoGorelli MarcoGorelli marked this pull request as ready for review January 18, 2021 17:34
@jreback jreback merged commit fa09c6e into pandas-dev:master Jan 20, 2021
@jreback
Copy link
Contributor

jreback commented Jan 20, 2021

thanks @MarcoGorelli this is a nice cleanup. in the future pls do these types of changes in smaller batches.

@MarcoGorelli MarcoGorelli deleted the refactor-rest-of-core branch January 20, 2021 17:36
nofarm3 pushed a commit to nofarm3/pandas that referenced this pull request Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants