Skip to content

Conversation

@anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 17, 2021

Before:

In [1]: np.dtype({"names": ["a"], "formats": [int], "offsets": [2]})
Out[1]: dtype({'names':['a'], 'formats':['<i8'], 'offsets':[2], 'itemsize':10})

After:

In [1]: np.dtype({"names": ["a"], "formats": [int], "offsets": [2]})
Out[1]: dtype({'names': ['a'], 'formats': ['<i8'], 'offsets': [2], 'itemsize': 10})

The version with spaces feels much more idiomatic to me...

@charris charris changed the title ENH: Add spaces after punctuation in dtype repr/str. MAINT: Add spaces after punctuation in dtype repr/str. Aug 18, 2021
Copy link
Contributor

@shubham11941140 shubham11941140 left a comment

Choose a reason for hiding this comment

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

This is a mistake. If you add a space before the function, it will changes the complete functioning of variable, Remove the spacing.

@eric-wieser
Copy link
Member

eric-wieser commented Aug 22, 2021

I think the old behavior might need to be preserved behind a legacy="1.21" printoption to avoid breaking doctests.

@anntzer
Copy link
Contributor Author

anntzer commented Aug 22, 2021

I tried looking into that, but overloading legacy to also support "1.21" seems slightly annoying because internally numpy simply checks for get_printoptions()["legacy"] == "1.13"; should these be converted to a string comparison (and hope that the legacy names always compare lexicographically) or use something like [*map(int, version.split("."))] or even a full-blown packaging.version.Version compare? (Also note that this option also show up on the C-side.)

@eric-wieser
Copy link
Member

I think probably just a sequence of comparisons to known versions is probably ok, rather than building a full parser.

@anntzer
Copy link
Contributor Author

anntzer commented Aug 22, 2021

OK, added the ability to switch back to the old repr.

Before:
```
In [1]: np.dtype({"names": ["a"], "formats": [int], "offsets": [2]})
Out[1]: dtype({'names':['a'], 'formats':['<i8'], 'offsets':[2], 'itemsize':10})
```

After:
```
In [1]: np.dtype({"names": ["a"], "formats": [int], "offsets": [2]})
Out[1]: dtype({'names': ['a'], 'formats': ['<i8'], 'offsets': [2], 'itemsize': 10})
```
Copy link
Member

@BvB93 BvB93 left a comment

Choose a reason for hiding this comment

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

Could you also add support for the new "1.21" legacy-option in the arrayprint.pyi stub file?
All you'd have to do is a bit of copy pasting with the following pattern:

- Optional[Literal[False, "1.13"]]
+ Optional[Literal[False, "1.13", "1.21"]]

@anntzer
Copy link
Contributor Author

anntzer commented Aug 23, 2021

done

@mattip
Copy link
Member

mattip commented Aug 26, 2021

Since this is, in some small sense, breaking backward compatibility, perhaps a release note is needed?

@anntzer
Copy link
Contributor Author

anntzer commented Aug 26, 2021

added changelog entry.

@mattip mattip requested a review from eric-wieser August 29, 2021 06:58
@seberg seberg added the triage review Issue/PR to be discussed at the next triage meeting label Sep 8, 2021
@seberg seberg removed the triage review Issue/PR to be discussed at the next triage meeting label Sep 22, 2021
@seberg
Copy link
Member

seberg commented Sep 22, 2021

We discussed this briefly and I think we can move ahead with this.

@seberg seberg changed the title MAINT: Add spaces after punctuation in dtype repr/str. ENH: Add spaces after punctuation in dtype repr/str. Sep 29, 2021
@seberg
Copy link
Member

seberg commented Sep 29, 2021

Thanks @anntzer lets give this a shot! If anyone stumbles on it or has concerns please make a note/open an issue.

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.

7 participants