From 097c225c6b733cd46c1ad044c695982f045c68e4 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 22 Apr 2013 14:03:25 -0400 Subject: [PATCH] BUG: Fix treasury loading. Make adjustments for using Python built-in ElementTree instead of lxml based lxml. lxml was edited out during pulling in of memory friendly loading of treasury curves, however some of the use of ETree was lxml specific. Mea culpa. --- zipline/data/treasuries.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/zipline/data/treasuries.py b/zipline/data/treasuries.py index 9a895ab8..c0897cfd 100644 --- a/zipline/data/treasuries.py +++ b/zipline/data/treasuries.py @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import re import requests @@ -84,6 +84,11 @@ class iter_to_stream(object): return result +def get_localname(element): + qtag = ET.QName(element.tag).text + return re.match("(\{.*\})(.*)", qtag).group(2) + + def get_treasury_source(): url = """\ http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData\ @@ -106,11 +111,11 @@ http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData\ for event, element in elements: if event == 'end': - tag = ET.QName(element.tag).localname + tag = get_localname(element) if tag == "entry": properties = element.find(properties_xpath[0]) - datum = {ET.QName(node.tag).localname: node.text - for node in properties.iterchildren() + datum = {get_localname(node): node.text + for node in properties.getchildren() if ET.iselement(node)} # clear the element after we've dealt with it: element.clear()