Skip to content
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

FIX-#4582: Inherit custom log layer #4583

Merged

Conversation

vnlitvinov
Copy link
Collaborator

@vnlitvinov vnlitvinov commented Jun 17, 2022

Signed-off-by: Vasily Litvinov fam1ly.n4me@yandex.ru

What do these changes do?

Fix inheritance of custom log layer. It's still possible to use PANDAS-API log layer in subclasses, but to do so one has to set it explicitly.

  • commit message follows format outlined here
  • passes flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
  • passes black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
  • signed commit with git commit -s
  • Resolves Modin custom logging layer is not inherited #4582
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date
  • added (Issue Number: PR title (PR Number)) and github username to release notes for next major release

@vnlitvinov vnlitvinov requested a review from a team as a code owner June 17, 2022 10:02
Signed-off-by: Vasily Litvinov <fam1ly.n4me@yandex.ru>
@codecov
Copy link

codecov bot commented Jun 17, 2022

Codecov Report

Merging #4583 (3961336) into master (af7f4ed) will increase coverage by 3.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4583      +/-   ##
==========================================
+ Coverage   86.55%   89.60%   +3.04%     
==========================================
  Files         230      231       +1     
  Lines       18435    18714     +279     
==========================================
+ Hits        15957    16768     +811     
+ Misses       2478     1946     -532     
Impacted Files Coverage Δ
modin/logging/class_logger.py 100.00% <100.00%> (ø)
modin/experimental/xgboost/test/test_default.py 70.00% <0.00%> (-30.00%) ⬇️
...s/pandas_on_dask/partitioning/virtual_partition.py 82.05% <0.00%> (-12.83%) ⬇️
...entations/pandas_on_dask/partitioning/partition.py 85.36% <0.00%> (-3.66%) ⬇️
modin/pandas/__init__.py 65.15% <0.00%> (-1.52%) ⬇️
modin/experimental/xgboost/xgboost.py 86.66% <0.00%> (-0.96%) ⬇️
modin/experimental/batch/test/test_pipeline.py 100.00% <0.00%> (ø)
modin/pandas/base.py 95.30% <0.00%> (+0.08%) ⬆️
...mentations/pandas_on_ray/partitioning/partition.py 93.57% <0.00%> (+1.83%) ⬆️
...tations/pandas_on_python/partitioning/partition.py 93.75% <0.00%> (+2.08%) ⬆️
... and 16 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@classmethod
def __init_subclass__(
cls,
modin_layer: str = "PANDAS-API",
modin_layer: Optional[str] = None,
Copy link
Collaborator

@naren-ponder naren-ponder Jun 17, 2022

Choose a reason for hiding this comment

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

Can we change Line 39 to be modin_layer: str = _modin_logging_layer? Does that work in Python? Then just adding cls._modin_logging_layer = modin_layer will fix this issue?

If not, can we also update the function comment to reflect the Optional[str] = None?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@naren-ponder I think the Pythonic way here is to default to None, I don't think what you describe will work because cls is not in scope in the signature.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@devin-petersohn Makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This won't work, but for the different reason.

In Python, default values are computed once at function declaration, so all instances of __init_subclass__ would get the default value as "PANDAS-API", effectively not achieving what this PR aims to achieve.

Copy link
Collaborator

@devin-petersohn devin-petersohn left a comment

Choose a reason for hiding this comment

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

LGTM, but will wait for @naren-ponder to agree.

@classmethod
def __init_subclass__(
cls,
modin_layer: str = "PANDAS-API",
modin_layer: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@naren-ponder I think the Pythonic way here is to default to None, I don't think what you describe will work because cls is not in scope in the signature.

naren-ponder
naren-ponder previously approved these changes Jun 19, 2022
Copy link
Collaborator

@naren-ponder naren-ponder left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

@classmethod
def __init_subclass__(
cls,
modin_layer: str = "PANDAS-API",
modin_layer: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@devin-petersohn Makes sense.

@@ -31,10 +31,12 @@ class ClassLogger:
This mixin must go first in class bases declaration to have the desired effect.
"""

_modin_logging_layer = "PANDAS-API"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can move this to a constant at the top of the file and it should work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you mean declare the string as a constant outside of the class (and re-use it in this line to set the variable) then yes, sure, it will work. But why?..

Unless we want to re-use the same constant in the @enable_logging...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, was responding to the comment here: #4583 (comment)

I thought you were saying this didn't work as we wanted it to, my mistake. Is this ok to merge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unless you want me to extract this constant (which I don't see much value in, TBH), it should be good to go.

@vnlitvinov
Copy link
Collaborator Author

@devin-petersohn @naren-ponder I had to merge to solve the conflict, please re-approve and let's merge the thing if no objections.

super().__init_subclass__(**kwargs)
enable_logging(modin_layer, class_name, log_level)(cls)
cls._modin_logging_layer = modin_layer

Choose a reason for hiding this comment

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

Does this change the _modin_logging_layer for all children of ClassLogger or just the children of ClassLogger and class Foo(ClassLogger)? For example, if there are classes:

Foo(ClassLogger, modin_layer="Custom"), Bar(Foo) and Other(ClassLogger), is Other guaranteed to have modin_layer="PANDAS-API"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it should be doing this way. The logic here is:

  1. Take the layer from declaration, but...
  2. If not specified, take from the class object (not instance! we don't have instances here yet, as it's the time of defining the class type)
  3. Class object at the time of construction won't have its own _modin_layer set up, so it would take one from the parent class, effectively inheriting
  4. Then, at the end we assign a new value in case someone has actually overridden the layer

Copy link
Collaborator

@RehanSD RehanSD left a comment

Choose a reason for hiding this comment

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

LGTM!

@devin-petersohn devin-petersohn merged commit 2de5c67 into modin-project:master Jun 27, 2022
@vnlitvinov vnlitvinov deleted the fix-log-level-inheritance branch June 27, 2022 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modin custom logging layer is not inherited
5 participants