Skip to content

Commit

Permalink
remove Py2vs3 code hybridized using sys.version
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste committed May 5, 2024
1 parent 051cfde commit 4189458
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
8 changes: 0 additions & 8 deletions nixio/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from collections.abc import OrderedDict
except ImportError:
from collections import OrderedDict
import sys

from .util import find as finders
from .compression import Compression
Expand Down Expand Up @@ -299,13 +298,6 @@ def create_data_frame(self, name="", type_="", col_dict=None,
return self.data_frames[objid]

util.check_entity_name_and_type(name, type_)
if (isinstance(col_dict, dict)
and not isinstance(col_dict, OrderedDict)
and sys.version_info[0] < 3):
raise TypeError("Cannot create a DataFrame from a dictionary "
"in Python 2 as the order of keys is not "
"preserved. Please use the OrderedDict class "
"from the collections module instead.")

if data is not None:
shape = len(data)
Expand Down
4 changes: 1 addition & 3 deletions nixio/test/test_data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# LICENSE file in the root of the Project.
import os
import time
import sys
import unittest
import numpy as np
import nixio as nix
Expand Down Expand Up @@ -277,8 +276,7 @@ def test_data_array_dtype(self):
assert da.dtype == test_data.dtype

bdata = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
if sys.version_info[0] == 3:
bdata = [bytes(x, 'UTF-8') for x in bdata]
bdata = [bytes(x, 'UTF-8') for x in bdata]

void_data = np.array(bdata, dtype='V1')
da = self.block.create_data_array('dtype_opaque', 'b', data=void_data)
Expand Down
10 changes: 4 additions & 6 deletions nixio/test/test_data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections.abc import OrderedDict
except ImportError:
from collections import OrderedDict
import sys


class TestDataFrame(unittest.TestCase):
Expand Down Expand Up @@ -219,11 +218,10 @@ def test_df_shape(self):
assert tuple(self.df1.df_shape) == (10, 5)
# create df with incorrect dimension to see if Error is raised
arr = np.arange(1000).reshape(10, 10, 10)
if sys.version_info[0] == 3:
with self.assertRaises(ValueError):
self.block.create_data_frame('err', 'err',
{'name': np.int64},
data=arr)
with self.assertRaises(ValueError):
self.block.create_data_frame('err', 'err',
{'name': np.int64},
data=arr)

def test_data_type(self):
assert self.df1.dtype[4] == np.int32
Expand Down

0 comments on commit 4189458

Please sign in to comment.