timvink / mkdocs-table-reader-plugin

MkDocs plugin that enables a markdown tag like {{ read_csv('table.csv') }} to directly insert various table formats into a page
https://timvink.github.io/mkdocs-table-reader-plugin/
MIT License
111 stars 18 forks source link

TypeError: `TypeError: tabulate() got an unexpected keyword argument 'keep_default_na'` #32

Closed wwarriner closed 1 year ago

wwarriner commented 1 year ago

Thanks for the plugin! We've been using it to great effect in our docs! We noticed a bug recently when we (inadvertently) upgraded to pandas 1.5.1.

Using pandas 1.5.1 we get a TypeError emitted by tabulate.tabulate() complaining of an unknown keyword. The error does not occur with 1.4.x.

I did some debugging while creating a minimal failing example and it looks like the dynamic kwargs parsing gets keep_default_na wrong, i.e., it becomes a to_markdown() arg instead of a read_csv() arg.

Failing example follows. I believe the file "test.csv" can be an empty file, since we're not testing content, but we tested it on a file with content. Test with pandas 1.5.1 and 1.4.4 to see the difference.

from mkdocs_table_reader_plugin.plugin import read_csv

read_csv("test.csv", keep_default_na=False)

We were surprised by this when our docs build broke out of nowhere. Lesson learned by us: pin package versions!

timvink commented 1 year ago

Yes, this bug caught me by surprise also! I think I've already solved it in the latest release (https://github.com/timvink/mkdocs-table-reader-plugin/releases/tag/v1.1.1). Can you check?

timvink commented 1 year ago

This works for me:

wget https://raw.githubusercontent.com/mcnakhaee/palmerpenguins/master/palmerpenguins/data/penguins-raw.csv
mv penguins-raw.csv test.csv

with

from mkdocs_table_reader_plugin.plugin import read_csv
read_csv("test.csv", keep_default_na=False)
timvink commented 1 year ago

And it breaks when I use table-reader v.1.1.0. with

TypeError: tabulate() got an unexpected keyword argument 'keep_default_na'
wwarriner commented 1 year ago

Ah I had neglected to try updating the plugin. Let me give that a go.

timvink commented 1 year ago

Thanks a lot for creating the issue and the debugging work you've already done! Really appreciate it. But happy I beat you to it 😉

wwarriner commented 1 year ago

It looks like it is up to 1.1.0 on conda, which is how we're receiving it. I see it at 1.1.1 on pypi, I'll give that a go for now.

Thanks for the kind words. I learned something from it, so it was worth it!

timvink commented 1 year ago

👍🏻