From 41894586f45c0e57a673d6b96ce041fee07b2f03 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sun, 5 May 2024 13:50:07 +0200 Subject: [PATCH] remove Py2vs3 code hybridized using sys.version --- nixio/block.py | 8 -------- nixio/test/test_data_array.py | 4 +--- nixio/test/test_data_frame.py | 10 ++++------ 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/nixio/block.py b/nixio/block.py index 3f7711d3..1604b0c2 100644 --- a/nixio/block.py +++ b/nixio/block.py @@ -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 @@ -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) diff --git a/nixio/test/test_data_array.py b/nixio/test/test_data_array.py index 07c90d3e..76257f75 100644 --- a/nixio/test/test_data_array.py +++ b/nixio/test/test_data_array.py @@ -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 @@ -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) diff --git a/nixio/test/test_data_frame.py b/nixio/test/test_data_frame.py index a7337345..06bc077c 100644 --- a/nixio/test/test_data_frame.py +++ b/nixio/test/test_data_frame.py @@ -9,7 +9,6 @@ from collections.abc import OrderedDict except ImportError: from collections import OrderedDict -import sys class TestDataFrame(unittest.TestCase): @@ -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