Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

List of lists of categorical data failing: Scatter ravel is performed before _process_unit_info() is called.#27035

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
borgesaugusto wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromborgesaugusto:iss_26743
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionslib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4657,14 +4657,14 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
# further processed by the rest of the function
linewidths = kwargs.pop('linewidth', None)
edgecolors = kwargs.pop('edgecolor', None)
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
# np.ma.ravel yields an ndarray, not a masked array,
# unless its argument is a masked array.
x = np.ma.ravel(x)
y = np.ma.ravel(y)
if x.size != y.size:
raise ValueError("x and y must be the same size")
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)

if s is None:
s = (20 if mpl.rcParams['_internal.classic_mode'] else
Expand Down
34 changes: 33 additions & 1 deletionlib/matplotlib/tests/test_category.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -249,11 +249,13 @@ def test_update_plot(self, plotter):
failing_test_cases = [("mixed", ['A', 3.14]),
("number integer", ['1', 1]),
("string integer", ['42', 42]),
("nested categorical", [["a", "b"], ["c", "d"]]),
("missing", ['12', np.nan])]

fids, fvalues = zip(*failing_test_cases)

plotters = [Axes.scatter, Axes.bar,
plotters = [pytest.param(Axes.scatter, marks=pytest.mark.xfail),
Axes.bar,
pytest.param(Axes.plot, marks=pytest.mark.xfail)]

@pytest.mark.parametrize("plotter", plotters)
Expand DownExpand Up@@ -321,3 +323,33 @@ def test_set_lim():
ax.plot(["a", "b", "c", "d"], [1, 2, 3, 4])
with warnings.catch_warnings():
ax.set_xlim("b", "c")


categorical_examples = [("nested categorical", [["a", "b"], ["c", "d"]]),
("nested with nan", [['0', np.nan], ["aa", "bb"]]),
("nested mixed", [[1, 'a'], ['b', np.nan]])]
Copy link
Member

Choose a reason for hiding this comment

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

By mixed, I meant what happens for [[1,2], ['a', 'b']] -> they all get cased to the same type b/c they get raveled into one list, so what happens then?

cids, cvalues = zip(*categorical_examples)


@pytest.mark.parametrize("xdata", cvalues, ids=cids)
@pytest.mark.parametrize("ydata", cvalues, ids=cids)
def test_nested_categorical(xdata, ydata):
ax = plt.figure().subplots()
ax.scatter(xdata, ydata)

xtexts = [xelement._text for xelement in ax.get_xticklabels()]

assert np.all(xtexts == np.ma.ravel(xdata))


@pytest.mark.parametrize("xdata", cvalues, ids=cids)
def test_nested_categorical_and_numerical(xdata):
ydata = [[0, 1], [2, 3]]
ax = plt.figure().subplots()
splot = ax.scatter(xdata, ydata)

xtexts = [xelement._text for xelement in ax.get_xticklabels()]
y_offset_processed = list(zip(*splot.get_offsets()))[1]

assert np.all(xtexts == np.ma.ravel(xdata))
assert np.all(np.ma.ravel(ydata) == y_offset_processed)

[8]ページ先頭

©2009-2025 Movatter.jp