Skip to content

CLN: some simple code cleanup #47438

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 2 commits into from
Aug 3, 2022
Merged

CLN: some simple code cleanup #47438

merged 2 commits into from
Aug 3, 2022

Conversation

hydratedguy
Copy link
Contributor

i've changed some inconsistencies on some magic methods's parameters and removed a return from a object initialization

@@ -640,7 +640,7 @@ def test_map_abc_mapping_with_missing(non_dict_mapping_subclass):
# https://github.com/pandas-dev/pandas/issues/29733
# Check collections.abc.Mapping support as mapper for Series.map
class NonDictMappingWithMissing(non_dict_mapping_subclass):
def __missing__(key):
Copy link
Member

Choose a reason for hiding this comment

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

this looks like it should fail in the status quo. does this change fix anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay, @jbrockmendel ! In this case, for example, it doesn't fail because missing is not directly called. Essentially these changes don't fix anything but code readability and correctness.

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Thanks @hydratedguy, really nice clean up.

Except the return, I think all the other methods should be failing if used. I checked __len__ and __getitem__ and they raised, if used as expected:

>>> class Foo:
...     def __len__(self, n):
...             return 1
... 
>>> foo = Foo()
>>> len(foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __len__() missing 1 required positional argument: 'n'
>>> class A:
...     def __getitem__(self):
...             return 1
... 
>>> a = A()
>>> a['b']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __getitem__() takes 1 positional argument but 2 were given

Do you mind having a look and see if the affected tests are being executed in the CI, if the classes are being used at all... I think we can probably clean up more than fixing the errors.

@hydratedguy
Copy link
Contributor Author

Thanks for the feedback, @datapythonista! Gonna do some exploring looking for what you mentioned then.

@hydratedguy
Copy link
Contributor Author

Hey @datapythonista! Sorry for the delay.

So, i didn't really know how to check if the tests were being executed in the CI, but i tried analyzing the classes on each test (how they are being used and for what purpose) and got to the conclusion that they're not wrong, just the parameters of the magic methods that are not entirely correct. I also checked if these cases appears in other places but they dont.

I really want to help, so if you can give me some pointers i really would appreciate it!

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM

@datapythonista
Copy link
Member

Sorry for the delay @hydratedguy. In general, there are few ways to check if a test is executed. One would be to check the list of skipped tests in one of the builds. The faster and most reliable could be to add an assert False into the test, push, and see if the CI fails.

I had another look, and I think in this case it's not the tests that are not being used, but the functionality itself. What I'd try is to delete the __len__ and __missing__ methods completely. They don't seem to be called. Maybe there is a reason why they are there, and then your fix will be fine. But if they are not needed, probably worth removing them instead of fixing them.

@datapythonista
Copy link
Member

Also, if you can please merge upstream into your branch, the CI should be working now.

@datapythonista datapythonista merged commit d6563c5 into pandas-dev:main Aug 3, 2022
@datapythonista
Copy link
Member

Thanks for the clean up @hydratedguy

If in a follow up PR you want to try to delete these methods, which may not be needed, that would be great.

noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants