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

PERF-#6224: Use 'Map' operator to retrieve categorical codes #6230

Merged
merged 2 commits into from
Jun 1, 2023

Conversation

dchigarev
Copy link
Collaborator

@dchigarev dchigarev commented Jun 1, 2023

What do these changes do?

After #6222 we guarantee that each partition has knowledge about the whole categorical table, meaning that we don't need to build the whole axis no more in order to retrieve valid categorical codes. So this PR basically replaces .fold(axis=0, ...) to the .map(...) in the .cat_codes implementation.

  • first commit message and PR title follow format outlined here

    NOTE: If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.

  • 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 Implement cat.codes using map rather than full-axis approach #6224
  • tests are passing
  • module layout described at docs/development/architecture.rst is up-to-date

…odes

Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Comment on lines -4039 to -4040
if ser.dtype != "category":
ser = ser.astype("category", copy=False)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since now, we shouldn't do this cast as disappearance of the categorical dtype will mean that we lost valid codes and should report an error

@dchigarev dchigarev marked this pull request as ready for review June 1, 2023 09:45
@dchigarev dchigarev requested a review from a team as a code owner June 1, 2023 09:45
anmyachev
anmyachev previously approved these changes Jun 1, 2023
Copy link
Collaborator

@anmyachev anmyachev left a comment

Choose a reason for hiding this comment

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

LGTM! @YarShev?

modin/core/dataframe/pandas/dataframe/dataframe.py Outdated Show resolved Hide resolved
@@ -1920,7 +1920,12 @@ def tree_reduce(
return self._compute_tree_reduce_metadata(axis.value, reduce_parts)

@lazy_metadata_decorator(apply_axis=None)
def map(self, func: Callable, dtypes: Optional[str] = None) -> "PandasDataframe":
def map(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably update the map's signature in modin/core/dataframe/base/dataframe/dataframe.py.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did that, however, it seems that there's already a mismatch with the base map as it additionally takes an axis parameter that is not defined in the pandas version of the dataframe

@abstractmethod
def map(
self,
function: Callable,
axis: Optional[Union[int, Axis]] = None,
dtypes: Optional[str] = None,
) -> "ModinDataframe":

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's align the signatures in a separate issue, please create one for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, #6231

Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
@YarShev YarShev merged commit 189ae67 into modin-project:master Jun 1, 2023
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement cat.codes using map rather than full-axis approach
3 participants