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

Add MapType as JSON-compatible #776

Merged
merged 8 commits into from
Sep 10, 2024
Merged

Add MapType as JSON-compatible #776

merged 8 commits into from
Sep 10, 2024

Conversation

srowen
Copy link
Contributor

@srowen srowen commented Sep 6, 2024

Description of changes:

dataframe_to_mds does not directly support the Spark Map type as there is no direct analog in streaming (?)
However, the dataframe_to_mds will accept "unsupported" Spark types if they are JSON-compatible, and if the user specifies type 'json' for the column.

However the logic of is_json_compatible doesn't include MapType, when a map is conceptually fine as a dict, and Spark uses simple dicts to represent such maps in pandas DFs. As long as the map's key and value types are JSON compatible, it should be considered JSON compatible.

With this change, it's possible to have columns including a map type successfully convert to JSON in an MDS file if the given type for the column is specified as 'json'.

Merge Checklist:

General

  • I have read the contributor guidelines
  • This is a documentation change or typo fix. If so, skip the rest of this checklist.
  • I certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the MosaicML team.
  • I have updated any necessary documentation, including README and API docs (if appropriate).

Tests

  • I ran pre-commit on my change. (check out the pre-commit section of prerequisites)
  • I have added tests that prove my fix is effective or that my feature works (if appropriate).
  • I ran the tests locally to make sure it pass. (check out testing)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes.

@srowen srowen added the enhancement New feature or request label Sep 6, 2024
Copy link
Collaborator

@snarayan21 snarayan21 left a comment

Choose a reason for hiding this comment

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

minor nits.

If possible can you add a simple unit test?

tests/base/converters/test_dataframe_to_mds.py Outdated Show resolved Hide resolved
tests/base/converters/test_dataframe_to_mds.py Outdated Show resolved Hide resolved
@srowen
Copy link
Contributor Author

srowen commented Sep 10, 2024

I think this is otherwise good to go - there are existing and one new test. I can add more too

Copy link
Collaborator

@snarayan21 snarayan21 left a comment

Choose a reason for hiding this comment

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

minor nit: variable name change. otherwise lgtm

@srowen
Copy link
Contributor Author

srowen commented Sep 10, 2024

@snarayan21 said I could merge after that change, so here goes!

@srowen srowen merged commit 989e354 into mosaicml:main Sep 10, 2024
7 checks passed
@srowen srowen deleted the map_json_spark branch September 10, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants