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

Cannot export concatenated Pandas Series to SBDF #77

Open
bbassett-tibco opened this issue Jan 2, 2025 · 0 comments
Open

Cannot export concatenated Pandas Series to SBDF #77

bbassett-tibco opened this issue Jan 2, 2025 · 0 comments

Comments

@bbassett-tibco
Copy link
Collaborator

Given the following script:

from spotfire import sbdf
import pandas as pd

T1 = pd.Series([1,  2,  3,  4,  5])
T2 = pd.Series([6,  7,  8,  9,  10])
T3 = pd.Series([11, 12, 13, 14, 15])

TX = pd.concat([T1, T2, T3])
sbdf.export_data(TX, "C:/tmp/out.sbdf")

Output:

Traceback (most recent call last):
  File "repro.py", line 9, in <module>
    sbdf.export_data(TX, "C:/tmp/out.sbdf")
  File "spotfire\\sbdf.pyx", line 1780, in spotfire.sbdf.export_data
  File "spotfire\\sbdf.pyx", line 995, in spotfire.sbdf._export_obj_series
  File "spotfire\\sbdf.pyx", line 1172, in spotfire.sbdf._export_infer_invalids
  File "C:\src\github\spotfire-python\venv\w312\Lib\site-packages\pandas\core\generic.py", line 1577, in __nonzero__
    raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

This is a result of the concatenation operation. The Series' index is Index([0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4], dtype='int64'), so requesting x[0] turns what we were expecting to be an array access operation into a subsetting operation. Thus, our truthyness check fails out because it's working on the wrong data type.

We should use Series.iloc instead of direct subsetting to fix the issue.

As a workaround, it is recommended to use the ignore_index=True parameter when doing the concatenation to avoid creating the duplicative series index.

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

1 participant