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

bug: plotting breaks when axis is passed to alt.X #18830

Closed
2 tasks done
MarcoGorelli opened this issue Sep 20, 2024 · 3 comments · Fixed by #18836
Closed
2 tasks done

bug: plotting breaks when axis is passed to alt.X #18830

MarcoGorelli opened this issue Sep 20, 2024 · 3 comments · Fixed by #18836
Labels
bug Something isn't working python Related to Python Polars

Comments

@MarcoGorelli
Copy link
Collaborator

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

In [8]: df = pl.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c': [7,8,9]})

In [9]: df.plot.line(x=alt.X('a', axis=alt.Axis(labelAngle=-90))).to_json()
---------------------------------------------------------------------------
SchemaValidationError                     Traceback (most recent call last)
Cell In[9], line 1
----> 1 df.plot.line(x=alt.X('a', axis=alt.Axis(labelAngle=-90))).to_json()

File ~/scratch/.venv/lib/python3.12/site-packages/altair/vegalite/v5/api.py:1899, in TopLevelMixin.to_json(self, validate, indent, sort_keys, format, ignore, context, **kwargs)
   1897 if context is None:
   1898     context = {}
-> 1899 spec = self.to_dict(
   1900     validate=validate, format=format, ignore=ignore, context=context
   1901 )
   1902 return json.dumps(spec, indent=indent, sort_keys=sort_keys, **kwargs)

File ~/scratch/.venv/lib/python3.12/site-packages/altair/vegalite/v5/api.py:3778, in Chart.to_dict(self, validate, format, ignore, context)
   3776     copy.data = core.InlineData(values=[{}])
   3777     return super(Chart, copy).to_dict(**kwds)
-> 3778 return super().to_dict(**kwds)

File ~/scratch/.venv/lib/python3.12/site-packages/altair/vegalite/v5/api.py:1813, in TopLevelMixin.to_dict(self, validate, format, ignore, context)
   1808 context["top_level"] = False
   1810 # TopLevelMixin instance does not necessarily have to_dict defined
   1811 # but due to how Altair is set up this should hold.
   1812 # Too complex to type hint right now
-> 1813 vegalite_spec: Any = super(TopLevelMixin, copy).to_dict(  # type: ignore[misc]
   1814     validate=validate, ignore=ignore, context=dict(context, pre_transform=False)
   1815 )
   1817 # TODO: following entries are added after validation. Should they be validated?
   1818 if is_top_level:
   1819     # since this is top-level we add $schema if it's missing

File ~/scratch/.venv/lib/python3.12/site-packages/altair/utils/schemapi.py:1076, in SchemaBase.to_dict(self, validate, ignore, context)
   1069         self.validate(result)
   1070     except jsonschema.ValidationError as err:
   1071         # We do not raise `from err` as else the resulting
   1072         # traceback is very long as it contains part
   1073         # of the Vega-Lite schema. It would also first
   1074         # show the less helpful ValidationError instead of
   1075         # the more user friendly SchemaValidationError
-> 1076         raise SchemaValidationError(self, err) from None
   1077 return result

SchemaValidationError: `Tooltip` has no parameter named 'axis'

Existing parameter names are:
shorthand      bin         format       title
aggregate      condition   formatType   type
bandPosition   field       timeUnit

See the help for `Tooltip` to read the full description of these parameters

Log output

No response

Issue description

this raises

Expected behavior

it shouldn't raise

Installed versions

--------Version info---------
Polars:              1.7.1
Index type:          UInt32
Platform:            Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python:              3.12.5 (main, Aug 14 2024, 05:08:31) [Clang 18.1.8 ]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               5.4.1
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
great_tables         0.11.0
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                2.1.1
openpyxl             <not installed>
pandas               2.2.2
pyarrow              17.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@MarcoGorelli MarcoGorelli added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer and removed needs triage Awaiting prioritization by a maintainer labels Sep 20, 2024
@AdrienDart
Copy link

Thank you for creating the issue and looking into it. FYI, I also got similar issues with .line(..., color=alt.Color(...).scale(...)) where parameter "scale" gets the same error

@bzm3r
Copy link

bzm3r commented Sep 22, 2024

I can confirm this issue: https://stackoverflow.com/questions/79010541

Also, whatever broke happened recently, because just about two to three weeks ago, this code worked okay.

@MarcoGorelli
Copy link
Collaborator Author

yup, it regressed in #18625, may be fixed by #18836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
3 participants