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

appending rows when there are dynamic columns #572

Closed
LucOevel opened this issue Dec 19, 2023 · 9 comments
Closed

appending rows when there are dynamic columns #572

LucOevel opened this issue Dec 19, 2023 · 9 comments

Comments

@LucOevel
Copy link

At the moment we cannot add rows (using append, rpush, lpush) when there is already a dynamic column: a function object can be added at the appropriate place in the row, but unlike a normal dynamic column it will not be executed.

@claudep
Copy link
Contributor

claudep commented Dec 19, 2023

Thanks for the report, are you planning a pull request?

@LucOevel
Copy link
Author

no... (I would if i could)

claudep added a commit to claudep/tablib that referenced this issue Dec 19, 2023
@claudep
Copy link
Contributor

claudep commented Dec 19, 2023

It would be great if you could test (or make test) the suggested patch above.

@LucOevel
Copy link
Author

LucOevel commented Dec 20, 2023

#------short test ------
print(tablib.__version__)

data = tablib.Dataset()

txt='''Greg Thorton
Dave Coutts
Joshua Ourisman'''

data.extend([item.split() for item in txt.splitlines()])

def dynamicColumn(row):
	return row[-1].upper()+'!'


data.append_col(dynamicColumn,'Calculated')  

data.append(('Brad','Montgomery', dynamicColumn))

#----------result: as before, dynamicColumn is not evaluated:
# 3.5.0
# Greg  |Thorton   |THORTON!
# Dave  |Coutts    |COUTTS!
# Joshua|Ourisman  |OURISMAN!
# Brad  |Montgomery|<function dynamicColumn at 0x000001A071042940>

@claudep
Copy link
Contributor

claudep commented Dec 20, 2023

Indeed, I worked on a similar but different use case in this patch. After adding a dynamic column, you can only provide the static values and the dynamic ones will be inserted automatically.

The use case in your latest example is to be able to add a dynamic value in any row, regardless of any previous data.append_col(func) call. I'll see if I can also integrate that use case.

@claudep
Copy link
Contributor

claudep commented Dec 20, 2023

@hugovk do you think that adding dynamic values in rows is worth implementing? We could argue that when inserting rows, you should be able to compute the values yourself.

@hugovk
Copy link
Member

hugovk commented Dec 21, 2023

I don't need it and am generally for less maintenance but not against it :)

@claudep
Copy link
Contributor

claudep commented Dec 21, 2023

@LucOevel, I committed the current patch which matches this issue description. Now feel free to create a new ticket for adding support to appending rows including callable values. However, please describe also the use case for that functionality, as you could as well prepare the values you are going to insert before adding the row.

@LucOevel
Copy link
Author

LucOevel commented Dec 22, 2023

As I understood it, the main point of dynamic columns is that their content automatically depends on other columns. So when other columns change, the dynamic values follow dynamically. Is that not what the name means? Having to pre-compute values when inserting a new row defeats that behavior, and those values will not be dynamic anymore. If the idea is that values can just as well be pre-computed instead of dynamic then why have dynamic values at all, right?
Why have dynamic elements when adding columns but not when adding rows?

BTW: @claudep can you provide an example of the use case you were thinking about? I seem to miss that point.

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