Skip to content

Commit

Permalink
writers: fix bug when hepdata_doi option is passed
Browse files Browse the repository at this point in the history
* Fixes 'TypeError: can only concatenate str (not "bytes") to str'.
* Pass 'hepdata_doi' in some tests to increase coverage.
* Also pass 'rivet_analysis_name' in one of the YODA writer tests.
* Bump version to 0.2.2.
  • Loading branch information
GraemeWatt committed Sep 30, 2020
1 parent b09f021 commit af3d858
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 35 deletions.
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/test_csvwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_no_dir_output(self, table_1_content, table_9_content):
def test_diroutput(self, oldhepdata_path, csv_path):
hepdata_converter._main(['-i', 'oldhepdata',
'-o', 'csv',
'-d', '10.17182/hepdata.62535.v1',
oldhepdata_path, self.current_tmp])

self.assertDirsEqual(self.current_tmp, csv_path, file_content_parser=lambda x: x)
3 changes: 2 additions & 1 deletion hepdata_converter/testsuite/test_rootwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_parse_all(self, test_submissions):
for idx, test_submission in enumerate(test_submissions):
output_file_path = os.path.join(self.current_tmp, 'data-{}.root'.format(idx))
hepdata_converter.convert(test_submission, output_file_path,
options={'output_format': 'root'})
options={'output_format': 'root',
'hepdata_doi': '10.17182/hepdata.12345.v1'})

self.assertNotEqual(os.stat(output_file_path).st_size, 0, 'output root file is empty')
4 changes: 3 additions & 1 deletion hepdata_converter/testsuite/test_yamlwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def test_single_file_output(self, oldhepdata_path, oldhepdata_file, oldhepdata_y
options={
'input_format': 'oldhepdata',
'output_format': 'yaml',
'single_file': True})
'single_file': True,
'hepdata_doi': '10.17182/hepdata.62535.v1'}
)

yaml_single_output_path = os.path.join(self.current_tmp, 'output.yaml')

Expand Down
4 changes: 3 additions & 1 deletion hepdata_converter/testsuite/test_yodawriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def test_simple_parse(self, yaml_simple_path, yoda_template):
output_file_path = os.path.join(self.current_tmp, 'datafile.yoda')
hepdata_converter.convert(yaml_simple_path, output_file_path,
options={'output_format': 'yoda',
'validator_schema_version': '0.1.0'})
'validator_schema_version': '0.1.0',
'hepdata_doi': '10.17182/hepdata.62535.v1',
'rivet_analysis_name': 'ATLAS_2012_I1203852'})

self.assertNotEqual(os.stat(output_file_path).st_size, 0, 'output yoda file is empty')
with open(output_file_path, 'r') as f:
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table1.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t1
#: name: Table 1
#: description: The measured fiducial cross sections. The first systematic uncertainty is the combined systematic uncertainty excluding luminosity, the second is the luminosity.
#: data_file: data1.yaml
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table2.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t2
#: name: Table 2
#: description: The measured total cross sections. The first systematic uncertainty is the combined systematic uncertainty excluding luminosity, the second is the luminosity.
#: data_file: data2.yaml
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table3.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t3
#: name: Table 3
#: description: Normalized ZZ fiducial cross section (multiplied by 10^6 for readability) in bins of the leading reconstructed dilepton pT for the 4 lepton channel. The first systematic uncertainty is detector systematics, the second is background systematic uncertainties.
#: data_file: data3.yaml
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table4.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t4
#: name: Table 4
#: description: Normalized ZZ fiducial cross section (multiplied by 10^6 for readability) in bins of the dilepton pT for the 2l2nu channel. The first systematic uncertainty is detector systematics, the second is background systematic uncertainties.
#: data_file: data4.yaml
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table5.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t5
#: name: Table 5
#: description: Normalized ZZ fiducial cross section (multiplied by 10^6 for readability) in bins of deltaPhi between the two leptons of the leading dileptons for the 4l channel. The first systematic uncertainty is detector systematics, the second is background systematic uncertainties.
UPDATE (30 APR 2014): extra significant digit added for first bin.
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table6.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t6
#: name: Table 6
#: description: Normalized ZZ fiducial cross section (multiplied by 10^6 for readability) in bins of deltaPhi between the two leptons for the 2l2nu channel. The first systematic uncertainty is detector systematics, the second is background systematic uncertainties.
#: data_file: data6.yaml
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table7.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t7
#: name: Table 7
#: description: Normalized ZZ fiducial cross section (multiplied by 10^6 for readability) in bins of the mass of the ZZ system for the 4l channel. The first systematic uncertainty is detector systematics, the second is background systematic uncertainties.
#: data_file: data7.yaml
Expand Down
1 change: 1 addition & 0 deletions hepdata_converter/testsuite/testdata/csv/full/Table8.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#: table_doi: 10.17182/hepdata.62535.v1/t8
#: name: Table 8
#: description: Normalized ZZ fiducial cross section (multiplied by 10^6 for readability) in bins of the transverse mass of the ZZ system for the 2l2nu channel. The first systematic uncertainty is detector systematics, the second is background systematic uncertainties.
#: data_file: data8.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ comment: |-
- No events with a jet for which ptJet > 25 GeV and |etaJet| < 4.5
- No events with a third lepton for which ptLepton > 10 GeV
- min(DeltaR(l,l)) > 0.3.
hepdata_doi: 10.17182/hepdata.62535.v1
record_ids:
- {id: 9863591, type: spires}
- {id: 1203852, type: inspire}
Expand Down Expand Up @@ -80,6 +81,7 @@ keywords:
values: [7000.0]
location: Data from Page 17 of preprint
name: Table 1
table_doi: 10.17182/hepdata.62535.v1/t1
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -110,6 +112,7 @@ keywords:
values: [7000.0]
location: Data from Page 20 of preprint
name: Table 2
table_doi: 10.17182/hepdata.62535.v1/t2
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -160,6 +163,7 @@ keywords:
values: [7000.0]
location: Data from Figure 8A
name: Table 3
table_doi: 10.17182/hepdata.62535.v1/t3
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -203,6 +207,7 @@ keywords:
values: [7000.0]
location: Data from Figure 8B
name: Table 4
table_doi: 10.17182/hepdata.62535.v1/t4
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -252,6 +257,7 @@ keywords:
values: [7000.0]
location: Data from Figure 9A
name: Table 5
table_doi: 10.17182/hepdata.62535.v1/t5
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -295,6 +301,7 @@ keywords:
values: [7000.0]
location: Data from Figure 9B
name: Table 6
table_doi: 10.17182/hepdata.62535.v1/t6
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -344,6 +351,7 @@ keywords:
values: [7000.0]
location: Data from Figure 10A
name: Table 7
table_doi: 10.17182/hepdata.62535.v1/t7
---
additional_resources: []
dependent_variables:
Expand Down Expand Up @@ -388,3 +396,4 @@ keywords:
values: [7000.0]
location: Data from Figure 10B
name: Table 8
table_doi: 10.17182/hepdata.62535.v1/t8
60 changes: 30 additions & 30 deletions hepdata_converter/testsuite/testdata/yoda/full.yoda
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d01-x01-y01
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d01-x01-y01
ErrorBreakdown: {0: {stat: {dn: -3.0, up: 3.3}, sys: {dn: -1.2, up: 1}, 'sys,lumi': {dn: -1, up: 1}}, 1: {stat: {dn: -3.5, up: 3.8}, sys: {dn: -1.5, up: 1.7}, 'sys,lumi': {dn: -1.2, up: 1.2}}, 2: {stat: {dn: -2.9, up: 3.1}, sys: {dn: -1.7, up: 1.7}, 'sys,lumi': {dn: -0.5, up: 0.5}}}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d01-x01-y01
Title: Table 1
Path: /REF/ATLAS_2012_I1203852/d01-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t1
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -12,11 +12,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER3D_V2 /REF/RIVET_ANALYSIS_NAME/d02-x01-y01
BEGIN YODA_SCATTER3D_V2 /REF/ATLAS_2012_I1203852/d02-x01-y01
ErrorBreakdown: {}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d02-x01-y01
Title: Table 2
Path: /REF/ATLAS_2012_I1203852/d02-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t2
Type: Scatter3D
---
# xval xerr- xerr+ yval yerr- yerr+ zval zerr- zerr+
Expand Down Expand Up @@ -53,11 +53,11 @@ Type: Scatter3D
END YODA_SCATTER3D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d03-x01-y01
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d03-x01-y01
ErrorBreakdown: {0: {stat: {dn: -1100, up: 1100}, 'sys,background': {dn: -15, up: 15}, 'sys,detector': {dn: -79, up: 79}}, 1: {stat: {dn: -1600, up: 1600}, 'sys,background': {dn: -15, up: 15}, 'sys,detector': {dn: -75, up: 75}}, 2: {stat: {dn: -490, up: 490}, 'sys,background': {dn: -2, up: 2}, 'sys,detector': {dn: -41, up: 41}}, 3: {stat: {dn: -60, up: 60}, 'sys,background': {dn: 0, up: 0}, 'sys,detector': {dn: -2, up: 2}}}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d03-x01-y01
Title: Table 3
Path: /REF/ATLAS_2012_I1203852/d03-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t3
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -68,11 +68,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d04-x01-y01
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d04-x01-y01
ErrorBreakdown: {0: {stat: {dn: -3340, up: 3340}, 'sys,background': {dn: -740, up: 740}, 'sys,detector': {dn: -80, up: 80}}, 1: {stat: {dn: -3210, up: 3210}, 'sys,background': {dn: -260, up: 260}, 'sys,detector': {dn: -200, up: 200}}, 2: {stat: {dn: -1490, up: 1490}, 'sys,background': {dn: -390, up: 390}, 'sys,detector': {dn: -120, up: 120}}}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d04-x01-y01
Title: Table 4
Path: /REF/ATLAS_2012_I1203852/d04-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t4
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -82,11 +82,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d05-x01-y01
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d05-x01-y01
ErrorBreakdown: {0: {stat: {dn: -69000, up: 69000}, 'sys,background': {dn: -10, up: 10}, 'sys,detector': {dn: -6600, up: 6600}}, 1: {stat: {dn: -100000, up: 100000}, 'sys,background': {dn: -400, up: 400}, 'sys,detector': {dn: -9000, up: 9000}}, 2: {stat: {dn: -80000, up: 80000}, 'sys,background': {dn: -300, up: 300}, 'sys,detector': {dn: -10000, up: 10000}}, 3: {stat: {dn: -50000, up: 50000}, 'sys,background': {dn: -300, up: 300}, 'sys,detector': {dn: -2000, up: 2000}}}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d05-x01-y01
Title: Table 5
Path: /REF/ATLAS_2012_I1203852/d05-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t5
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -97,11 +97,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d06-x01-y01
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d06-x01-y01
ErrorBreakdown: {0: {stat: {dn: -4400, up: 4400}, 'sys,background': {dn: -1900, up: 1900}, 'sys,detector': {dn: -300, up: 300}}, 1: {stat: {dn: -2630, up: 2630}, 'sys,background': {dn: -280, up: 280}, 'sys,detector': {dn: -230, up: 230}}, 2: {stat: {dn: -1210, up: 1210}, 'sys,background': {dn: -480, up: 480}, 'sys,detector': {dn: -60, up: 60}}}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d06-x01-y01
Title: Table 8
Path: /REF/ATLAS_2012_I1203852/d06-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t6
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -111,11 +111,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d07-x01-y01
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d07-x01-y01
ErrorBreakdown: {}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d07-x01-y01
Title: Table 9
Path: /REF/ATLAS_2012_I1203852/d07-x01-y01
Title: doi:10.17182/hepdata.62535.v1/t7
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -134,11 +134,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d07-x01-y02
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d07-x01-y02
ErrorBreakdown: {0: {error: {dn: -0.0, up: 0.0}}, 1: {error: {dn: -0.51, up: 0.41}}, 2: {error: {dn: -0.26, up: 0.41}}, 3: {error: {dn: -0.19, up: 0.12}}, 4: {error: {dn: -0.15, up: 0.16}}, 5: {error: {dn: -0.16, up: 0.19}}, 6: {error: {dn: -0.55, up: 0.56}}, 7: {error: {dn: -0.15, up: 0.1}}, 8: {error: {dn: -0.1, up: 0.11}}, 9: {error: {dn: -0.08, up: 0.08}}, 10: {error: {dn: -0.33, up: 0.33}}, 11: {error: {dn: -0.14, up: 0.17}}}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d07-x01-y02
Title: Table 9
Path: /REF/ATLAS_2012_I1203852/d07-x01-y02
Title: doi:10.17182/hepdata.62535.v1/t7
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -157,11 +157,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d07-x01-y03
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d07-x01-y03
ErrorBreakdown: {}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d07-x01-y03
Title: Table 9
Path: /REF/ATLAS_2012_I1203852/d07-x01-y03
Title: doi:10.17182/hepdata.62535.v1/t7
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand All @@ -180,11 +180,11 @@ Type: Scatter2D
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/RIVET_ANALYSIS_NAME/d07-x01-y04
BEGIN YODA_SCATTER2D_V2 /REF/ATLAS_2012_I1203852/d07-x01-y04
ErrorBreakdown: {}
IsRef: 1
Path: /REF/RIVET_ANALYSIS_NAME/d07-x01-y04
Title: Table 9
Path: /REF/ATLAS_2012_I1203852/d07-x01-y04
Title: doi:10.17182/hepdata.62535.v1/t7
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
Expand Down
2 changes: 1 addition & 1 deletion hepdata_converter/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# this file ideally should only contain __version__ declaration, as anything else
# may break setup.py and PyPI uploads
__version__ = '0.2.1'
__version__ = '0.2.2'
2 changes: 1 addition & 1 deletion hepdata_converter/writers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Writer(GetConcreteSubclassMixin, OptionInitMixin, metaclass=abc.ABCMeta):
def __init__(self, single_file_output, *args, **kwargs):
OptionInitMixin.__init__(self, options=kwargs)
self.single_file_output = single_file_output
self.hepdata_doi = kwargs['hepdata_doi'].encode('utf8', 'replace') if 'hepdata_doi' in kwargs else ''
self.hepdata_doi = kwargs['hepdata_doi'] if 'hepdata_doi' in kwargs else ''

@classmethod
def create_dir(cls, path):
Expand Down

0 comments on commit af3d858

Please sign in to comment.