cms-l1t-offline / cms-l1t-analysis

0 stars 21 forks source link

Python 3 compatibility #151

Open kreczko opened 6 years ago

kreczko commented 6 years ago

As CMS is preparing to support Python 3, so should we.

The first culprit is

File "./bin/get_l1Analysis", line 119, in <module>
    f.write(ETSUM_HEADER)
TypeError: a bytes-like object is required, not 'str'

https://github.com/cms-l1t-offline/cms-l1t-analysis/blob/master/bin/get_l1Analysis#L117

kreczko commented 6 years ago

One of the last outstanding issues is

    def _expand_lumi_ranges(lumi_ranges):
        '''
            Expands `[[1,4], [10,12]` to `[1,2,3,4,10,11,12]`
        '''
        result = np.array(map(_expand_lumi_range, lumi_ranges))
>       return np.concatenate(result).ravel()
E       TypeError: len() of unsized object
kreczko commented 6 years ago

Turns out that map(_expand_lumi_range, lumi_ranges) is a generator in Python 3 and numpy.array will not resolve it, but

result = list(map(_expand_lumi_range, lumi_ranges))
return np.concatenate(result).ravel()

works

kreczko commented 6 years ago

It seems I will have to revise the target. Starting January 2019 pandas, numpy and matplotlib will be dropping Python 2 support. Since we depend on them it would be good to go a similar path

kreczko commented 5 years ago

Python 2.7 tests are now dropped on the dev branch.