Closed ewyluda closed 1 year ago
Has any of these versions changed recently?
Also, please can you create a self-contained, runnable, minimal reproducer?
here is a reproducer:
I am using Google Colab to run this code, the reproducible example below is for a single series, my code functions similarly with the exception of multiple series being requested versus two series here.
What's supposed to happen: an API request is made, prettytable is used to display the ASCII data and then export the tables as individual csv files (for each series ID) to a directory.
When did the error occur: I only started receiving the error today, I have been running the code successfully for 6-8 months until today. I am using Google Colab notebook to run the code, so I am not aware of any updates.
import requests
import json
import prettytable
headers = {'Content-type': 'application/json'}
data = json.dumps({"seriesid": ['CUUR0000SA0','SUUR0000SA0'],"startyear":"2012", "endyear":"2023"})
p = requests.post('https://api.bls.gov/publicAPI/v1/timeseries/data/', data=data, headers=headers)
json_data = json.loads(p.text)
for series in json_data['Results']['series']:
x=prettytable.PrettyTable(["series id","year","period","value","footnotes"])
seriesId = series['seriesID']
for item in series['data']:
year = item['year']
period = item['period']
value = item['value']
footnotes=""
for footnote in item['footnotes']:
if footnote:
footnotes = footnotes + footnote['text'] + ','
if 'M01' <= period <= 'M12':
x.add_row([seriesId,year,period,value,footnotes[0:-1]])
output = open(seriesId + '.txt','w')
output.write (x.get_csv_string())
output.close()
Thanks, it's working for me, I get these files:
What versions are you using? I have:
>>> import sys
>>> sys.version
'3.11.2 (main, Feb 16 2023, 02:55:59) [Clang 14.0.0 (clang-1400.0.29.202)]'
>>> import prettytable
>>> prettytable.__version__
'3.6.0'
(The reproducer could be made more minimal by using some hardcoded values rather than downloading via an API, it took 1m16s to run and at first I thought it had hung.)
ok just found out my python version is 3.9.16 (main, Dec 7 2022, 01:11:51) [GCC 9.4.0] and prettytable is 0.7.2
I need to figure out how to install the latest version in Colab, currently I've just been using
pip install prettytable
import prettytable
Aha! That makes sense, get_csv_string()
was added in 1.0.
https://github.com/jazzband/prettytable/blob/main/CHANGELOG.md#prettytable-10---october-4-2020
Good luck with updating Colab.
PS Try something like pip install --upgrade prettytable
!pip install prettytable --upgrade
worked, thank you!
x.get_csv_string() no longer works... I've been using this method for 6 months or so without any issue, went to rerun my code today and i keep getting an attribute error... any suggestions?