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

[MRG] Fix build-in CLI extraction to Excel #373

Merged
merged 1 commit into from
May 23, 2023

Conversation

ipa-bak
Copy link
Contributor

@ipa-bak ipa-bak commented May 17, 2023

This PR fixes #372

The calls to the Pandas Excel writer where no longer compatible with recent versions.

  • The to_excel() method does not have an "encoding" keyword argument.
  • The method to save to file is now called "close" instead of "save".

Tested with the following related package versions:

  • openpyxl 3.1.2
  • pandas 2.0.1

The calls to the Pandas Excel writer where no longer compatible with recent
versions.
* The to_excel() method does not have an "encoding" keyword argument.
* The method to save to file is now called "close" instead of "save".
@ipa-bak ipa-bak changed the title Fix build-in CLI extraction to Excel [MRG] Fix build-in CLI extraction to Excel May 17, 2023
@ipa-bak
Copy link
Contributor Author

ipa-bak commented May 17, 2023

Hi @foarsitter and @MartinThoma , I saw the discussion in #343 . I f you want me to open this PR against some other fork, let me known. Unfortunately I cannot offer general help with maintaining this project, I am already stretch thin with too many other tasks.

@foarsitter
Copy link
Contributor

@ipa-bak can you confirm that this change is covered in tests.test_cli.test_cli_output_format?

@ipa-bak
Copy link
Contributor Author

ipa-bak commented May 22, 2023

Should be covered by

camelot/tests/test_cli.py

Lines 137 to 142 in e3b9c73

outfile = os.path.join(tempdir, "health.xlsx")
result = runner.invoke(
cli,
["--format", "excel", "--output", outfile, "stream", infile],
)
assert result.exit_code == 0, f"Output: {result.output}"
.
At least that is the case that failed for me without this change and works with this change in.

Note that I did not call it with stream, but with lattice, but that should make zero difference.

@foarsitter foarsitter merged commit 44b4e68 into camelot-dev:master May 23, 2023
5 checks passed
AaronPed added a commit to AaronPed/camelot that referenced this pull request Jul 13, 2023
Fix build-in CLI extraction to Excel (camelot-dev#373)
@4WvgqJu
Copy link

4WvgqJu commented Aug 4, 2023

And source code starting at section 598 in file core.py?
I can't see changes at "Files Changend".
I've changed it for myself into:

    def to_excel(self, path, **kwargs):
        """Writes Table to an Excel file.

        For kwargs, check :meth:`pandas.DataFrame.to_excel`.

        Parameters
        ----------
        path : str
            Output filepath.

        """
        kw = {
            "sheet_name": f"page-{self.page}-table-{self.order}"
        }
        '''
        kw = {
            "sheet_name": f"page-{self.page}-table-{self.order}",
            "encoding": "utf-8",
        }
        '''
        kw.update(kwargs)
        writer = pd.ExcelWriter(path)
        self.df.to_excel(writer, **kw)
        writer.close()
        '''
        writer.save()
        ''' 

Br. F.

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

Successfully merging this pull request may close these issues.

Export to Excel (camelot CLI interface): TypeError: to_excel() got an unexpected keyword argument 'encoding'
3 participants