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-#6793: use pandas.api.types.pandas_dtype instead of np.dtype for some more places #6794

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

anmyachev
Copy link
Collaborator

@anmyachev anmyachev commented Dec 2, 2023

What do these changes do?

  • 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 Use pandas.api.types.pandas_dtype instead of np.dtype in all Modin codebase to allow work with pandas dtypes #6793
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date

@anmyachev anmyachev force-pushed the issue6793 branch 2 times, most recently from 9569c46 to 3203fac Compare December 3, 2023 20:52
new_dtype = dtype
new_dtype = pandas.api.types.pandas_dtype(dtype)
if hasattr(dtype, "_is_materialized"):
_ = dtype._materialize_categories()
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 this case dtype cannot be serialized by Dask.

modin/core/dataframe/algebra/binary.py Show resolved Hide resolved
Comment on lines 1564 to 1653
new_dtype = pandas.api.types.pandas_dtype(dtype)
if hasattr(dtype, "_is_materialized"):
_ = dtype._materialize_categories()
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe like this? pandas_dtype returns exactly the same object if a categorical is passed

>>> cat = pd.CategoricalDtype([1, 2])
>>> pd.api.types.pandas_dtype(cat) is cat
True
Suggested change
new_dtype = pandas.api.types.pandas_dtype(dtype)
if hasattr(dtype, "_is_materialized"):
_ = dtype._materialize_categories()
if isinstance(dtype, LazyCategoricalProxy):
new_dtype = dtype
else:
new_dtype = pandas.api.types.pandas_dtype(dtype)

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 LazyCategoricalProxy case, new_dtype will remain with non-materialized categories, which will lead to a problem with Dask.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we then add a dask specific branching here and label it as a hack? Otherwise, materializing lazy categories without a need, breaks the whole sense of them being lazy

@anmyachev anmyachev marked this pull request as draft January 17, 2024 11:56
Copy link
Collaborator

@dchigarev dchigarev left a comment

Choose a reason for hiding this comment

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

Mostly looks good, left a few comments

modin/core/dataframe/algebra/binary.py Show resolved Hide resolved
modin/core/dataframe/algebra/binary.py Show resolved Hide resolved
Comment on lines 1564 to 1653
new_dtype = pandas.api.types.pandas_dtype(dtype)
if hasattr(dtype, "_is_materialized"):
_ = dtype._materialize_categories()
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we then add a dask specific branching here and label it as a hack? Otherwise, materializing lazy categories without a need, breaks the whole sense of them being lazy

@anmyachev anmyachev marked this pull request as ready for review March 15, 2024 16:00
@anmyachev
Copy link
Collaborator Author

@dchigarev ready for review

@anmyachev
Copy link
Collaborator Author

@dchigarev ping, I think all your comments have been answered.

…some more places in Modin code

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
@dchigarev dchigarev merged commit 478b86c into modin-project:master Mar 28, 2024
37 checks passed
@anmyachev anmyachev deleted the issue6793 branch March 28, 2024 09:09
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.

Use pandas.api.types.pandas_dtype instead of np.dtype in all Modin codebase to allow work with pandas dtypes
2 participants