Skip to content

Array formatting fixes for sparse and NEP-18 arrays. #3211

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

Merged
merged 14 commits into from
Aug 16, 2019

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Aug 13, 2019

I also did a bit of cleanup (e.g., renaming methods) in xarray.core.formatting.

Sparse arrays were previously not shown in the Dataset repr:

<xarray.Dataset>
Dimensions:  (x: 4)
Coordinates:
    y        (x) int64 ...
Dimensions without coordinates: x
Data variables:
    a        (x) float64 ..."""

Now they are:

<xarray.Dataset>
Dimensions:  (x: 4)
Coordinates:
    y        (x) int64 <COO: shape=(4,), nnz=3, fill_value=0>
Dimensions without coordinates: x
Data variables:
    a        (x) float64 <COO: shape=(4,), nnz=4, fill_value=0.0>"""
  • Tests added
  • Passes black . && mypy . && flake8

I also did a bit of cleanup (e.g., renaming methods) in xarray.core.formatting.

Sparse arrays were previously not shown in the Dataset repr:

    <xarray.Dataset>
    Dimensions:  (x: 4)
    Coordinates:
        y        (x) int64 ...
    Dimensions without coordinates: x
    Data variables:
        a        (x) float64 ..."""

Now they are:

    <xarray.Dataset>
    Dimensions:  (x: 4)
    Coordinates:
        y        (x) int64 <COO: shape=(4,), nnz=3, fill_value=0>
    Dimensions without coordinates: x
    Data variables:
        a        (x) float64 <COO: shape=(4,), nnz=4, fill_value=0.0>"""
@pep8speaks
Copy link

pep8speaks commented Aug 13, 2019

Hello @shoyer! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 962:89: E501 line too long (90 > 88 characters)

Line 101:89: E501 line too long (91 > 88 characters)
Line 102:89: E501 line too long (95 > 88 characters)

Line 193:89: E501 line too long (91 > 88 characters)
Line 194:89: E501 line too long (89 > 88 characters)

Comment last updated at 2019-08-15 20:33:50 UTC

@@ -178,24 +178,22 @@ def test_repr(self):
data = create_test_data(seed=123)
data.attrs["foo"] = "bar"
# need to insert str dtype at runtime to handle both Python 2 & 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# need to insert str dtype at runtime to handle both Python 2 & 3

Copy link
Member Author

Choose a reason for hiding this comment

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

we still need this for supporting different endiannesses

@crusaderky
Copy link
Contributor

Possible improvements:

  • Take a slice from the front of sparse arrays, densify it, and show the array contents just like you can see them for dense arrays
  • Represent dask arrays differently when they have a sparse _meta

@shoyer
Copy link
Member Author

shoyer commented Aug 15, 2019

  • Take a slice from the front of sparse arrays, densify it, and show the array contents just like you can see them for dense arrays

This is a good idea, but it will require slightly more complex logic to pull items only from the front of an array. I don't have a lot of time to iterate on this right now, so I'm going to leave it for later.

Represent dask arrays differently when they have a sparse _meta

I have now added in meta to the repr for dask arrays. PTAL.

@crusaderky
Copy link
Contributor

Re legacy dask: #3222

@shoyer shoyer merged commit e678ec9 into pydata:master Aug 16, 2019
@shoyer shoyer deleted the sparse-formatting branch August 16, 2019 19:14
@jthielen jthielen mentioned this pull request Aug 24, 2019
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.

5 participants