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

FEAT-#4245: Define base interface for dataframe exchange protocol #4246

Merged
merged 16 commits into from Feb 25, 2022

Conversation

YarShev
Copy link
Collaborator

@YarShev YarShev commented Feb 22, 2022

Signed-off-by: Igoshev, Yaroslav yaroslav.igoshev@intel.com

What do these changes do?

  • 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 Define base interface for dataframe exchange protocol #4245
  • tests 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

… protocol

Signed-off-by: Igoshev, Yaroslav <yaroslav.igoshev@intel.com>
@YarShev YarShev requested a review from a team as a code owner February 22, 2022 13:47
@codecov
Copy link

codecov bot commented Feb 22, 2022

Codecov Report

Merging #4246 (44827f8) into master (47b8a1c) will increase coverage by 3.02%.
The diff coverage is 98.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4246      +/-   ##
==========================================
+ Coverage   86.80%   89.82%   +3.02%     
==========================================
  Files         201      205       +4     
  Lines       16795    16977     +182     
==========================================
+ Hits        14579    15250     +671     
+ Misses       2216     1727     -489     
Impacted Files Coverage Δ
modin/conftest.py 92.77% <95.00%> (+9.23%) ⬆️
...ataframe/base/exchange/dataframe_protocol/utils.py 98.27% <98.27%> (ø)
modin/core/dataframe/base/exchange/__init__.py 100.00% <100.00%> (ø)
...frame/base/exchange/dataframe_protocol/__init__.py 100.00% <100.00%> (ø)
...rame/base/exchange/dataframe_protocol/dataframe.py 100.00% <100.00%> (ø)
...core/execution/dispatching/factories/dispatcher.py 93.33% <100.00%> (+0.18%) ⬆️
.../core/execution/dispatching/factories/factories.py 87.70% <100.00%> (+0.20%) ⬆️
modin/core/io/io.py 98.41% <100.00%> (+0.02%) ⬆️
modin/core/storage_formats/base/query_compiler.py 99.21% <100.00%> (+<0.01%) ⬆️
...odin/core/storage_formats/pandas/query_compiler.py 96.18% <100.00%> (+<0.01%) ⬆️
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47b8a1c...44827f8. Read the comment docs.

Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
YarShev and others added 6 commits February 22, 2022 18:35
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Igoshev, Yaroslav <yaroslav.igoshev@intel.com>
@@ -556,35 +556,6 @@ def __constructor__(self, *args, **kwargs):
"""
return type(self)(*args, **kwargs)

def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why moved? We should be able to export both kinds of objects (Series and DataFrame), so the __dataframe__ method has to be located in the base class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The spec is only about a DataFrame object, but not a Series.

Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
@@ -256,6 +256,7 @@ jobs:
- run: python -m pytest -n 2 modin/test/test_partition_api.py
- run: python -m pytest modin/test/test_utils.py
- run: python -m pytest asv_bench/test/test_utils.py
- run: python -m pytest modin/test/exchange_protocol/base
Copy link
Collaborator

Choose a reason for hiding this comment

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

The most convenient location for the tests to be placed would be near the protocol's code (modin/core/dataframe/base/dataframe/protocol/tests). However, this location creates import conflicts between conftest.py and modin.utils, in particular, this assertion is failing:

modin/modin/conftest.py

Lines 24 to 26 in dae9891

assert (
"modin.utils" not in sys.modules
), "Do not import modin.utils before patching, or tests could fail"

So it was decided to move the tests to a higher level.

Copy link
Collaborator Author

@YarShev YarShev Feb 23, 2022

Choose a reason for hiding this comment

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

That is okay. We actually want to move all tests in one place as part of #3645. However, I would like to generalize the structure a bit. See latest commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In order to be ready for adding other exchange protocols.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree with @YarShev.

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.

Overall structure LGTM!

Signed-off-by: Igoshev, Yaroslav <yaroslav.igoshev@intel.com>
@devin-petersohn
Copy link
Collaborator

@YarShev this looks much improved. Is it ready to merge?

@YarShev
Copy link
Collaborator Author

YarShev commented Feb 24, 2022

@devin-petersohn, yes, the structure looks good to me too. I think we can merge this.

@@ -363,6 +363,61 @@ def to_numpy(self, **kwargs): # noqa: PR02

# END To NumPy

# Dataframe exchange protocol

def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use @abc.abstractmethod decorator? How it's done for to_pandas method. Same for from_dataframe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In order to be able to instantiate a DataFrame with the underlying QC at this line - https://github.com/modin-project/modin/pull/4246/files#diff-028a94e3db5c73c7ddedc6f7b6efb79e07e1360bb1401531b0a9f5d0ca1f1928R55. Otherwise, you will get the error: Can't instantiate abstract class ... with abstract methods from_dataframe, to_dataframe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, but isn't that the main way Modin defines an interface?

I propose to define the method as abstract in BaseQueryCompiler class, and let the child classes: PandasQueryCompiler and DFAlgQueryCompiler throw NotImplementedError exception.

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, BaseQueryCompiler should define the interface to be overridden by child classes. We could either make the methods abstract now or as part of efforts discussed here. I don't have strong preferences on this. However, doing that what you proposed

I propose to define the method as abstract in BaseQueryCompiler class, and let the child classes: PandasQueryCompiler and DFAlgQueryCompiler throw NotImplementedError exception.

You will still be getting the error mentioned above. We should override the methods in TestQC.

Do you think we should make the methods abstract in the Base QC as part of this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If there is no hurry, we can do it here. Otherwise, we need to flag this question and implement it elsewhere. (Yes, it also need to de done in TestQC)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There shouldn't be strong efforts to do that so let's put it here. However, this PR should be merged by end of today.

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 also need to de done in TestQC

That is not quite correct. We should override the methods in TestQC only, PandasQC and OmnisciQC will override the methods as part of new issues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@vnlitvinov
Copy link
Collaborator

I would rather we first get data-apis/dataframe-api#74 merged, then vendor that.

@YarShev
Copy link
Collaborator Author

YarShev commented Feb 24, 2022

To not block development of the implementations for pandas and omnisci storage formats, we can merge this PR after @anmyachev's comment is resolved. Once the API is stabilized in the data-apis repo, we'll just copy it from there and paste it here.

Signed-off-by: Igoshev, Yaroslav <yaroslav.igoshev@intel.com>
@YarShev
Copy link
Collaborator Author

YarShev commented Feb 24, 2022

TeamCity jobs failed because of our internal fault. TeamCity agents should be added/registered newly. We are working on that. Meanwhile, I think we can omit these jobs and the changes are ready to be merged

if is_datetime64_dtype(dtype):
# Selecting the first char of resolution string:
# dtype.str -> '<M8[ns]'
resolution = re.findall(r"\[(.*)\]", dtype.str)[0][:1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't there a better way?.. looks weird

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can fix that as part of a separate PR too.

modin/test/exchange/dataframe_protocol/base/test_sanity.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@vnlitvinov vnlitvinov left a comment

Choose a reason for hiding this comment

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

Let's Get This Moving!

@dchigarev dchigarev merged commit fc539c3 into modin-project:master Feb 25, 2022
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.

Define base interface for dataframe exchange protocol
5 participants