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

module 'pyarrow' has no attribute 'from_pandas' #555

Open
DanielKerrigan opened this issue Dec 17, 2024 · 2 comments
Open

module 'pyarrow' has no attribute 'from_pandas' #555

DanielKerrigan opened this issue Dec 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@DanielKerrigan
Copy link

I'm running into the following error when using VegaFusion 2.0.1 with pandas 2.1.4, Altair 5.5.0, and pyarrow 18.1.0:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/IPython/core/formatters.py:1036, in MimeBundleFormatter.__call__(self, obj, include, exclude)
   1033     method = get_real_method(obj, self.print_method)
   1035     if method is not None:
-> 1036         return method(include=include, exclude=exclude)
   1037     return None
   1038 else:

File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/altair/vegalite/v5/api.py:3682, in TopLevelMixin._repr_mimebundle_(self, *args, **kwds)
   3680 else:
   3681     if renderer := renderers.get():
-> 3682         return renderer(dct)

File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/altair/utils/display.py:232, in HTMLRenderer.__call__(self, spec, **metadata)
    230 kwargs = self.kwargs.copy()
    231 kwargs.update(**metadata, output_div=self.output_div)
--> 232 return spec_to_mimebundle(spec, format="html", **kwargs)

File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/altair/utils/mimebundle.py:129, in spec_to_mimebundle(spec, format, mode, vega_version, vegaembed_version, vegalite_version, embed_options, engine, **kwargs)
    127 internal_mode: Literal["vega-lite", "vega"] = mode
    128 if using_vegafusion():
--> 129     spec = compile_with_vegafusion(spec)
    130     internal_mode = "vega"
    132 # Default to the embed options set by alt.renderers.set_embed_options

File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/altair/utils/_vegafusion_data.py:273, in compile_with_vegafusion(vegalite_spec)
    271 # Pre-evaluate transforms in vega spec with vegafusion
    272 row_limit = data_transformers.options.get("max_rows", None)
--> 273 transformed_vega_spec, warnings = vf.runtime.pre_transform_spec(
    274     vega_spec,
    275     vf.get_local_tz(),
    276     inline_datasets=inline_tables,
    277     row_limit=row_limit,
    278 )
    280 # Check from row limit warning and convert to MaxRowsError
    281 handle_row_limit_exceeded(row_limit, warnings)

File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/vegafusion/runtime.py:408, in VegaFusionRuntime.pre_transform_spec(self, spec, local_tz, default_input_tz, row_limit, preserve_interactivity, inline_datasets, keep_signals, keep_datasets)
    347 """
    348 Evaluate supported transforms in an input Vega specification
    349 
   (...)
    405         were eligible for pre-transforming
    406 """
    407 local_tz = local_tz or get_local_tz()
--> 408 imported_inline_dataset = self._import_inline_datasets(
    409     inline_datasets, get_inline_column_usage(spec)
    410 )
    412 new_spec, warnings = self.runtime.pre_transform_spec(
    413     spec,
    414     local_tz=local_tz,
   (...)
    420     keep_datasets=parse_variables(keep_datasets),
    421 )
    423 return new_spec, warnings

File ~/miniconda3/envs/version-test/lib/python3.10/site-packages/vegafusion/runtime.py:303, in VegaFusionRuntime._import_inline_datasets(self, inline_datasets, inline_dataset_usage)
    300         imported_inline_datasets[name] = Table(inner_value)
    301     else:
    302         # Older pandas, convert through pyarrow
--> 303         imported_inline_datasets[name] = Table(pa.from_pandas(inner_value))
    304 elif isinstance(value, dict):
    305     # Let narwhals import the dict using a default backend
    306     df_nw = nw.from_dict(value, native_namespace=_get_default_namespace())

AttributeError: module 'pyarrow' has no attribute 'from_pandas'

To reproduce this error, I used the following Conda environment:

name: version-test
channels:
  - conda-forge
dependencies:
  - python=3.10
  - pandas=2.1.4
  - notebook
  - altair-all=5.5.0

and then ran a notebook containing this example:

import altair as alt
import pandas as pd

alt.data_transformers.enable("vegafusion")

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)
@MarcoGorelli
Copy link
Contributor

thanks for the report

# Older pandas, convert through pyarrow
imported_inline_datasets[name] = Table(pa.from_pandas(inner_value))

this should probably be pa.Table.from_pandas?

@jonmmease
Copy link
Collaborator

Ahh, yeah that's a good point. Thanks for looking into it @MarcoGorelli

@jonmmease jonmmease added the bug Something isn't working label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants