Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix collections coerce float #21818

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 2 commits into from
Dec 3, 2021

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Nov 30, 2021

PR Summary

Collections set_offset was coercing to float, which ruins any units we want to do. Closes #21803

Needs tests....

Tested with

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10)
y = np.sin(x)
d = x * np.timedelta64(24, 'h') + np.datetime64('2021-11-29')

sc = plt.scatter(d, y) # showsw a plot
sc.set_offsets(list(zip(d, y)))
plt.show()

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@jklymak jklymak force-pushed the fix-collections-coerce-float branch 2 times, most recently from dcc7c9b to 958a741 Compare November 30, 2021 15:31
@jklymak jklymak marked this pull request as ready for review November 30, 2021 15:31
@jklymak jklymak added the PR: bugfix Pull requests that fix identified bugs label Nov 30, 2021
@jklymak jklymak added this to the v3.5.1 milestone Nov 30, 2021
@jklymak
Copy link
Member Author

jklymak commented Nov 30, 2021

.. perhaps not necessary for 3.5.1 as I suspect this has been like this for years...

@jklymak jklymak force-pushed the fix-collections-coerce-float branch from 958a741 to 585a000 Compare December 1, 2021 13:47
Comment on lines 551 to 553
offsets[:, 0] = self.convert_xunits(offsets[:, 0])
offsets[:, 1] = self.convert_yunits(offsets[:, 1])
offsets = np.asarray(offsets, 'float')
Copy link
Member

Choose a reason for hiding this comment

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

If we're going to re-cast, is there any reason to hang on to the original array? Can we do np.column_stack((convertx(...), converty(...)))?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, done. Not sure it is any more elegant, but probably better to convert the x and y arrays separately to float anyway (they can be object arrays, even though convert_xunits has been called, which actually strikes me as a problem in convert_x/yunits.

@jklymak jklymak merged commit 392dd40 into matplotlib:main Dec 3, 2021
@jklymak jklymak deleted the fix-collections-coerce-float branch December 3, 2021 14:00
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Dec 3, 2021
dstansby added a commit that referenced this pull request Dec 3, 2021
…818-on-v3.5.x

Backport PR #21818 on branch v3.5.x (Fix collections coerce float)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bugfix Pull requests that fix identified bugs topic: units and array ducktypes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: using set_offsets on scatter object raises TypeError
3 participants