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

schemaerror alt.HConcatChart(...) #2767

Closed
ghasempouri1984 opened this issue Dec 21, 2022 · 11 comments
Closed

schemaerror alt.HConcatChart(...) #2767

ghasempouri1984 opened this issue Dec 21, 2022 · 11 comments

Comments

@ghasempouri1984
Copy link

ghasempouri1984 commented Dec 21, 2022

Hello,

When I try to plot side-by-side graphs with alt.concat I get schemaerror message. Would you please help me to resolve the issue?

Python 3.8.10
altair 4.2
jsonschema 4.16

healthPlot = alt.Chart(data2).mark_circle().encode(
    x = "Health (Life Expectancy)",
    y = "Happiness Score",
    color = alt.Color("Region", scale = alt.Scale(scheme="spectral")),
    tooltip = ("Country", "Happiness Score")
)


generosityPlot = alt.Chart(data2).mark_circle().encode(
    x = "Generosity",
    y = "Happiness Score",
    color = alt.Color("Region", scale = alt.Scale(scheme="spectral")),
    tooltip = ("Country", "Happiness Score")
)

generosityPlot | healthPlot

SchemaError Traceback (most recent call last)
File path to venv\lib\site-packages\altair\vegalite\v4\api.py:384, in TopLevelMixin.to_dict(self, *args, **kwargs)
381 kwargs["context"] = context
383 try:
--> 384 dct = super(TopLevelMixin, copy).to_dict(*args, **kwargs)
385 except jsonschema.ValidationError:
386 dct = None

File pathto venv\lib\site-packages\altair\utils\schemapi.py:338, in SchemaBase.to_dict(self, validate, ignore, context)
336 if validate:
337 try:
--> 338 self.validate(result)
339 except jsonschema.ValidationError as err:
340 raise SchemaValidationError(self, err)

File path to venv\lib\site-packages\altair\utils\schemapi.py:443, in SchemaBase.validate(cls, instance, schema)
441 schema = cls._schema
442 resolver = jsonschema.RefResolver.from_schema(cls._rootschema or cls._schema)
--> 443 return jsonschema.validate(
444 instance, schema, cls=cls._validator, resolver=resolver
445 )

File path to venv\lib\site-packages\jsonschema\validators.py:1117, in validate(instance, schema, cls, *args, **kwargs)
1114 if cls is None:
1115 cls = validator_for(schema)
-> 1117 cls.check_schema(schema)
1118 validator = cls(schema, *args, **kwargs)
1119 error = exceptions.best_match(validator.iter_errors(instance))

File path to venv\lib\site-packages\jsonschema\validators.py:231, in create..Validator.check_schema(cls, schema, format_checker)
226 validator = Validator(
227 schema=cls.META_SCHEMA,
228 format_checker=format_checker,
229 )
230 for error in validator.iter_errors(schema):
--> 231 raise exceptions.SchemaError.create_from(error)

SchemaError: '#/definitions/TopLevelNormalizedHConcatSpec' is not a 'uri-reference'

Failed validating 'format' in metaschema['properties']['$ref']:
{'format': 'uri-reference', 'type': 'string'}

On schema['$ref']:
'#/definitions/TopLevelNormalizedHConcatSpec'

@joelostblom
Copy link
Contributor

Please include a reproducible example which includes sample data so that someone can try it out on their machine.

@ghasempouri1984
Copy link
Author

ghasempouri1984 commented Dec 21, 2022

WHR_2016.csv

import pandas as pd
import altair as alt

data2 = pd.read_csv("WHR_2016.csv")

healthPlot = alt.Chart(data2).mark_circle().encode(
    x = "Health (Life Expectancy)",
    y = "Happiness Score",
    color = alt.Color("Region", scale = alt.Scale(scheme="spectral")),
    tooltip = ("Country", "Happiness Score")
)

generosityPlot = alt.Chart(data2).mark_circle().encode(
    x = "Generosity",
    y = "Happiness Score",
    color = alt.Color("Region", scale = alt.Scale(scheme="spectral")),
    tooltip = ("Country", "Happiness Score")
)

generosityPlot|healthPlot

@ghasempouri1984
Copy link
Author

ghasempouri1984 commented Dec 21, 2022

Please include a reproducible example which includes sample data so that someone can try it out on their machine.

i did now. anyway, the problem is not about data. in another machine i can run it. i do not know why. the versions of python and pandas and altair are the same.

@binste
Copy link
Contributor

binste commented Dec 22, 2022

I cannot reproduce the error with your example and the versions Python 3.8.10, altair 4.2, jsonschema 4.16. What version of Pandas are you using? Could you try reinstalling the packages or recreating the virtual environment in case you are using one?

@ghasempouri1984
Copy link
Author

both pandas 1.5.1, 1.5.2.
i did reinstalling packages, env, and also pycharm ide. it did not work.
and as I said on another pc machine it works.

@binste
Copy link
Contributor

binste commented Dec 24, 2022

Thanks @ghasempouri1984! Could you please run the following code blocks in order and post all outputs?

This one should still produce the error:

import altair as alt
import pandas as pd
import jsonschema
from pprint import pprint

data2 = pd.read_csv("WHR_2016.csv")

healthPlot = alt.Chart(data2).mark_circle().encode(
    x = "Health (Life Expectancy)",
    y = "Happiness Score",
    color = alt.Color("Region", scale = alt.Scale(scheme="spectral")),
    tooltip = ("Country", "Happiness Score")
)

generosityPlot = alt.Chart(data2).mark_circle().encode(
    x = "Generosity",
    y = "Happiness Score",
    color = alt.Color("Region", scale = alt.Scale(scheme="spectral")),
    tooltip = ("Country", "Happiness Score")
)

final_chart = (generosityPlot | healthPlot)
final_chart

And now the following lines individually:

final_chart._rootschema
final_chart._schema
alt.__version__
jsonschema.__version__
pprint(final_chart.to_dict(validate=False))

@ghasempouri1984
Copy link
Author

ghasempouri1984 commented Dec 24, 2022

Thanks for your reply @binste
I did it. yes it reproduced error. and the following is:

SchemaError: '#/definitions/TopLevelNormalizedHConcatSpec' is not a 'uri-reference'

Failed validating 'format' in metaschema['properties']['$ref']:
{'format': 'uri-reference', 'type': 'string'}

On schema['$ref']:
'#/definitions/TopLevelNormalizedHConcatSpec'

final_chart._rootschema
output:
output.txt

final_chart._schema
{'$ref': '#/definitions/TopLevelNormalizedHConcatSpec'}

alt.__version__
4.2.0

jsonschema.__version__
4.17.3

pprint(final_chart.to_dict(validate=False))
output:
output2.txt

@binste
Copy link
Contributor

binste commented Dec 24, 2022

Thank you! This is very likely the same issue as #2705. You should be able to resolve it by downgrading jsonschema to before 4.17, e.g. pip install jsonschema==4.16.0. If it works, I think this issue can be closed and we can keep looking into the other one.

@ghasempouri1984
Copy link
Author

Thank you! You actually have jsonschema 4.17 installed, could you downgrade jsonschema to 4.16 with pip install jsonschema==4.16.0 and see if it works? If yes, it's probably the same issue as #2705 in which case I think this issue can be closed and we can keep looking into the other one.

I tested before with 4.16 and also 4.3.3. The same error.

@binste
Copy link
Contributor

binste commented Dec 24, 2022

Just want to be fully sure that this is the case and there is nothing else going on. After downgrading, what is the output of jsonschema.__version__ for you in the same notebook/pycharm session where you get the error?

@ghasempouri1984
Copy link
Author

@binste thanks for your quick reply.
I restarted the venv, and did pip install jsonschema 4.16.
it worked :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants