Skip to content

Conversation

@akihironitta
Copy link
Contributor

@akihironitta akihironitta commented Oct 31, 2020

What does this PR do?

Fixes #4400.

TODO:

Add tests for:

  • str_to_bool_or_str
  • str_to_bool
  • is_picklable
  • clean_namespace
  • parse_class_init_keys
  • get_init_args <- NEED HELP Thank you @ethanwharris!
  • collect_init_args <- NEED HELP Thank you @ethanwharris!
  • flatten_dict
  • AttributeDict

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@akihironitta
Copy link
Contributor Author

I believe pytorch_lightning.utilities.parsing.lightning_hasattr should return either True or False as Python built-in hasattr returns so. However, with the current implementation, lightning_hasattr returns non-bool object in some cases.
https://github.com/PyTorchLightning/pytorch-lightning/blob/ebc1b23fa38d54e9805aa4356867369f064c7031/pytorch_lightning/utilities/parsing.py#L177

@akihironitta
Copy link
Contributor Author

Also, when model doesn't have attribute, lightning_getattr(model, attribute) should raise AttributeError rather than ValueError.
https://github.com/PyTorchLightning/pytorch-lightning/blob/ebc1b23fa38d54e9805aa4356867369f064c7031/pytorch_lightning/utilities/parsing.py#L219

@pep8speaks
Copy link

pep8speaks commented Nov 1, 2020

Hello @akihironitta! Thanks for updating this PR.

Line 33:1: E731 do not assign a lambda expression, use a def

Comment last updated at 2021-03-02 01:16:20 UTC

@akihironitta
Copy link
Contributor Author

akihironitta commented Nov 1, 2020

Python built-in has_attr is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not, as described in docs. Let's follow the implementation here as well so that we can simplify lightning_hasattr.

@codecov
Copy link

codecov bot commented Nov 1, 2020

Codecov Report

Merging #4460 (3c2d65b) into master (3645eb1) will decrease coverage by 2%.
The diff coverage is 89%.

@@           Coverage Diff           @@
##           master   #4460    +/-   ##
=======================================
- Coverage      93%     91%    -2%     
=======================================
  Files         160     159     -1     
  Lines       11402   11365    -37     
=======================================
- Hits        10654   10358   -296     
- Misses        748    1007   +259     

tchaton
tchaton previously requested changes Nov 2, 2020
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

Great addition.

Would you mind adding some tests ?

Best,
T.C

@akihironitta
Copy link
Contributor Author

I don't think I am capable of writing tests for collect_init_args and get_init_args. It would be wonderful if someone helps me...

@akihironitta akihironitta changed the title [WIP] Add tests/utilities/test_parsing.py [WIP][NEED HELP] Add tests/utilities/test_parsing.py Nov 4, 2020
@akihironitta
Copy link
Contributor Author

akihironitta commented Feb 17, 2021

I need help in adding the tests for:

  • get_init_args
  • collect_init_args

I couldn't trace what get_init_args behaves, so I'm wondering if someone who's familiar with this part could add the tests...

@akihironitta akihironitta changed the title [WIP][NEED HELP] Add tests/utilities/test_parsing.py [NEED HELP] Add tests/utilities/test_parsing.py Feb 17, 2021
@akihironitta akihironitta changed the title [NEED HELP] Add tests/utilities/test_parsing.py Add tests/utilities/test_parsing.py Feb 19, 2021
@ethanwharris
Copy link
Member

@akihironitta I added tests for get_init_args and collect_init_args, hope that helps!

@akihironitta
Copy link
Contributor Author

@ethanwharris Thank you so much for your help!

@akihironitta akihironitta marked this pull request as ready for review March 1, 2021 01:39
@akihironitta akihironitta requested a review from tchaton March 1, 2021 01:39
@mergify mergify bot removed the has conflicts label Mar 1, 2021
@Borda Borda enabled auto-merge (squash) March 1, 2021 09:36
@Borda Borda added the ready PRs ready to be merged label Mar 1, 2021
@Borda Borda dismissed tchaton’s stale review March 4, 2021 18:58

mind re-review

@Borda Borda merged commit 48a10f1 into Lightning-AI:master Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration feature Is an improvement or enhancement ready PRs ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for parsing.py