From 978495d1f2a1db6638931480cae6bc8b6fed0ebf Mon Sep 17 00:00:00 2001 From: Dan J Bower Date: Fri, 22 Mar 2024 21:59:27 +0100 Subject: [PATCH 1/2] Raise ParserWarning not ParserError for Pandas > 1.3.5 Raise a ParserWarning to avoid the ParserError `pandas.errors.ParserError: Defining usecols with out-of-bounds indices is not allowed.` when using Pandas>1.3.5. Now a warning is output for the problematic lines (which relate to comments in the JANAF data). Tested on an example txt file: https://janaf.nist.gov/tables/H-066.txt --- thermochem/janaf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/thermochem/janaf.py b/thermochem/janaf.py index c169987..59ba4c6 100644 --- a/thermochem/janaf.py +++ b/thermochem/janaf.py @@ -77,7 +77,6 @@ def __init__(self, rawdata_text): self.description = self.rawdata_text.splitlines()[0] # Read the text file into a DataFrame. - # TODO: adjust usecols length to be within bounds, Pandas deprecation data = pd.read_csv( StringIO(self.rawdata_text), skiprows=2, @@ -85,7 +84,7 @@ def __init__(self, rawdata_text): delimiter=r'[\t\s]+', engine='python', names=['T', 'Cp', 'S', '[G-H(Tr)]/T', 'H-H(Tr)', 'Delta_fH', 'Delta_fG', 'log(Kf)'], - usecols=range(8) # Ignore extra columns -- those are caused by comments in the text file + on_bad_lines='warn' ) self.rawdata = data From f35dc37211441a9feb6d425de65b0f4c2179b1e6 Mon Sep 17 00:00:00 2001 From: Dan J Bower Date: Fri, 22 Mar 2024 22:18:12 +0100 Subject: [PATCH 2/2] Update Pandas version This is related to pull request #30, which requires at least Pandas 1.3.0 for the `on_bad_lines` keyword argument to be available. See https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a990203..dff7809 100644 --- a/README.rst +++ b/README.rst @@ -55,7 +55,7 @@ automatically with any of the installation instructions provided. - SciPy >= 0.6.0 -- pandas >= 0.17.0 +- pandas >= 1.3.0 Development -----------