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

fix: Avoid sphinx error "Code Execution failed:NameError: name 'format_locale' is not defined" #3503

Merged
merged 3 commits into from
Jul 27, 2024

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Jul 25, 2024

Occurs during doc build, due to both variables being used without a defintion.

./doc/Lib/site-packages/sphinxext_altair/altairplot.py:261:
UserWarning: altair-plot: ./altair/doc/user_guide/customization.rst:826 Code Execution failed:
NameError: name 'format_locale' is not defined
  warnings.warn(message, stacklevel=1)

…mat_locale' is not defined"

Occurs during doc build, due to both variables being used without a defintion.

```log
.\doc\Lib\site-packages\sphinxext_altair\altairplot.py:261:
UserWarning: altair-plot: .\altair\doc\user_guide/customization.rst:826 Code Execution failed:
NameError: name 'format_locale' is not defined
  warnings.warn(message, stacklevel=1)
```
@dangotbanned
Copy link
Member Author

Another option could be just to remove that .. altair-plot::, since the one after has valid code.

Localization
------------
The preferred format of numbers, dates, and currencies varies by language and locale.
Vega-Altair takes advantage of `D3's localization support`_ to make it easy to configure
the locale for your chart using the global ``alt.renderers.set_embed_options`` function.

.. altair-plot::
   :output: none

   import altair as alt
   alt.renderers.set_embed_options(format_locale=None, time_format_locale=None)

Here ``format_locale`` and ``time_format_locale`` may either be D3 format dictionaries,
or strings with the names of pre-defined locales. For example, here we use the
Italian locale (named ``it-IT``) for both currencies and dates:

.. altair-plot::
   :output: none

   import altair as alt
   from vega_datasets import data

   alt.renderers.set_embed_options(format_locale="it-IT", time_format_locale="it-IT")

   source = data.stocks.url
   chart = alt.Chart(source).mark_area().transform_filter('year(datum.date) == 2009').encode(
       x='date:T',
       y=alt.Y('price:Q', axis=alt.Axis(format="$.0f")),
       color='symbol:N'
   )
   chart

@mattijn
Copy link
Contributor

mattijn commented Jul 25, 2024

I agree with your comment that it makes more sense to render it as a code-block and not as a sphinxext-altair altair-plot directive

@dangotbanned
Copy link
Member Author

dangotbanned commented Jul 26, 2024

I agree with your comment that it makes more sense to render it as a code-block and not as a sphinxext-altair altair-plot directive

@mattijn I agree with you on that, but that wasn't what I meant 😄

I meant this change:

diff --git a/doc/user_guide/customization.rst b/doc/user_guide/customization.rst
index 77eaf707..9759669b 100644
--- a/doc/user_guide/customization.rst
+++ b/doc/user_guide/customization.rst
@@ -823,12 +823,6 @@ The preferred format of numbers, dates, and currencies varies by language and lo
 Vega-Altair takes advantage of `D3's localization support`_ to make it easy to configure
 the locale for your chart using the global ``alt.renderers.set_embed_options`` function.
 
-.. altair-plot::
-   :output: none
-
-   import altair as alt
-   alt.renderers.set_embed_options(format_locale=None, time_format_locale=None)
-
 Here ``format_locale`` and ``time_format_locale`` may either be D3 format dictionaries,
 or strings with the names of pre-defined locales. For example, here we use the
 Italian locale (named ``it-IT``) for both currencies and dates:

Another option could be just to remove that .. altair-plot::, since the one after has valid code.

This one has to repeat all of what was in the other anyway, but uses real arguments:

.. altair-plot:: # <------
   :output: none # <------

   import altair as alt # <------
   from vega_datasets import data

   alt.renderers.set_embed_options(format_locale="it-IT", time_format_locale="it-IT") # <------

   source = data.stocks.url
   chart = alt.Chart(source).mark_area().transform_filter('year(datum.date) == 2009').encode(
       x='date:T',
       y=alt.Y('price:Q', axis=alt.Axis(format="$.0f")),
       color='symbol:N'
   )
   chart

I don't think there's any information lost as a result vs actual

image

@mattijn
Copy link
Contributor

mattijn commented Jul 27, 2024

Also good👍

@dangotbanned
Copy link
Member Author

Also good👍

Thanks @mattijn should be ready to merge now

@mattijn mattijn merged commit ced6553 into vega:main Jul 27, 2024
13 checks passed
@mattijn
Copy link
Contributor

mattijn commented Jul 27, 2024

Thanks for the PR!🥳

@dangotbanned dangotbanned deleted the fix-sphinx-warn-locale branch July 27, 2024 19:14
@joelostblom joelostblom added the bug label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants