Skip to content

Commit

Permalink
Merge pull request #541 from a-detiste/master
Browse files Browse the repository at this point in the history
remove Python2 crumbs
  • Loading branch information
achilleas-k authored Jul 24, 2024
2 parents 915a232 + 9f3d24c commit 444aae5
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 84 deletions.
2 changes: 1 addition & 1 deletion docs/source/examples/lif.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np


class LIF(object):
class LIF:

def __init__(self, stepsize=0.0001, offset=1.6, tau_m=0.025, tau_a=0.02, da=0.0, D=3.5):
self.stepsize = stepsize # simulation stepsize [s]
Expand Down
20 changes: 4 additions & 16 deletions nixio/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.

try:
from sys import maxint
except ImportError:
from sys import maxsize as maxint
from sys import maxsize

import numpy as np
from inspect import isclass
from six import string_types
try:
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 @@ -302,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 Expand Up @@ -358,8 +347,7 @@ def create_data_frame(self, name="", type_="", col_dict=None,
if col_dict is not None:
for nam, dt in col_dict.items():
if isclass(dt):
if any(issubclass(dt, st) for st in string_types) \
or issubclass(dt, np.string_):
if issubclass(dt, str) or issubclass(dt, np.string_):
col_dict[nam] = util.vlen_str_dtype
if 'U' in str(dt) or dt == np.string_:
col_dict[nam] = util.vlen_str_dtype
Expand Down Expand Up @@ -398,7 +386,7 @@ def find_sources(self, filtr=lambda _: True, limit=None):
:rtype: list of nixio.Source
"""
if limit is None:
limit = maxint
limit = maxsize
return finders._find_sources(self, filtr, limit)

def pprint(self, indent=2, max_length=120, extra=True, start_depth=0):
Expand Down
2 changes: 1 addition & 1 deletion nixio/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import util


class Container(object):
class Container:
"""
Container acts as an interface to container groups in the backend. In the
case of HDF5, this is a group that is used as a container for other groups.
Expand Down
5 changes: 1 addition & 4 deletions nixio/data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.
from __future__ import (absolute_import, division, print_function)
try:
from collections.abc import Iterable
except ImportError:
Expand All @@ -20,7 +19,6 @@
from .data_set import DataSet
from .datatype import DataType
from .section import Section
from six import string_types
import csv


Expand Down Expand Up @@ -56,8 +54,7 @@ def append_column(self, column, name, datatype=None):
raise ValueError("Too much entries for column in this dataframe")
if datatype is None:
datatype = DataType.get_dtype(column[0])
if isclass(datatype) and any(issubclass(datatype, st)
for st in string_types):
if isclass(datatype) and issubclass(datatype, str):
datatype = util.vlen_str_dtype
dt_arr = [(n, dty) for n, dty in zip(self.column_names, self.dtype)]
dt_arr.append((name, datatype))
Expand Down
2 changes: 1 addition & 1 deletion nixio/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np


class DataSet(object):
class DataSet:
"""
Data IO object for DataArray.
"""
Expand Down
5 changes: 2 additions & 3 deletions nixio/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.
from numbers import Integral, Real
from six import string_types
from packaging import version

import numpy as np
Expand All @@ -16,7 +15,7 @@
BOOLS = (bool, np.bool_)


class DataType(object):
class DataType:
UInt8 = np.uint8
UInt16 = np.uint16
UInt32 = np.uint32
Expand Down Expand Up @@ -45,7 +44,7 @@ def get_dtype(cls, value):
return cls.Int64
elif isinstance(value, Real):
return cls.Double
elif isinstance(value, string_types):
elif isinstance(value, str):
return cls.String
else:
raise ValueError("Unknown type for value {}".format(value))
Expand Down
4 changes: 2 additions & 2 deletions nixio/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _inst_item(self, item):
return cls(self._parent, idx)


class DimensionLink(object):
class DimensionLink:
"""
Links a Dimension to a data object (DataArray or DataFrame).
Expand Down Expand Up @@ -223,7 +223,7 @@ def _data_object_type(self):
return self._h5group.get_attr("data_object_type")


class Dimension(object):
class Dimension:

def __init__(self, nixfile, data_array, index):
dimgroup = data_array._h5group.open_group("dimensions")
Expand Down
2 changes: 1 addition & 1 deletion nixio/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from . import util


class Entity(object):
class Entity:

def __init__(self, nixfile, nixparent, h5group):
util.check_entity_id(h5group.get_attr("entity_id"))
Expand Down
5 changes: 2 additions & 3 deletions nixio/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from .data_frame import DataFrame
from .link_type import LinkType
from .exceptions import UnsupportedLinkType
from six import string_types
from .util import util


class Feature(object):
class Feature:

def __init__(self, nixfile, nixparent, h5group):
util.check_entity_id(h5group.get_attr("entity_id"))
Expand Down Expand Up @@ -53,7 +52,7 @@ def link_type(self):

@link_type.setter
def link_type(self, link_type):
if isinstance(link_type, string_types):
if isinstance(link_type, str):
link_type = link_type.lower()
link_type = LinkType(link_type)
self._h5group.set_attr("link_type", link_type.value)
Expand Down
11 changes: 4 additions & 7 deletions nixio/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import os
import gc
import numpy as np
from sys import maxsize
from warnings import warn

try:
from sys import maxint
except ImportError:
from sys import maxsize as maxint
import h5py

from .hdf5.h5group import H5Group
Expand Down Expand Up @@ -54,7 +51,7 @@ def can_read(nixfile):
return False


class FileMode(object):
class FileMode:
ReadOnly = 'r'
ReadWrite = 'a'
Overwrite = 'w'
Expand Down Expand Up @@ -82,7 +79,7 @@ def make_fcpl():
return fcpl


class File(object):
class File:

def __init__(self, path, mode=FileMode.ReadWrite,
compression=Compression.Auto,
Expand Down Expand Up @@ -478,7 +475,7 @@ def find_sections(self, filtr=lambda _: True, limit=None):
:rtype: list of nixio.Section
"""
if limit is None:
limit = maxint
limit = maxsize
return finders._find_sections(self, filtr, limit)

@property
Expand Down
2 changes: 1 addition & 1 deletion nixio/hdf5/h5dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .. import util


class H5DataSet(object):
class H5DataSet:

def __init__(self, parent, name, dtype=None, shape=None,
compression=False):
Expand Down
2 changes: 1 addition & 1 deletion nixio/hdf5/h5group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .. import util


class H5Group(object):
class H5Group:

def __init__(self, parent, name, create=False):
self._parent = parent
Expand Down
6 changes: 3 additions & 3 deletions nixio/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections import Sequence, Iterable
from enum import Enum
from numbers import Number
from six import string_types, ensure_str, ensure_text
from six import ensure_str, ensure_text
import numpy as np

from .datatype import DataType
Expand Down Expand Up @@ -268,7 +268,7 @@ def values(self, vals):
self.delete_values()
return

if not isinstance(vals, (Sequence, Iterable)) or isinstance(vals, string_types):
if not isinstance(vals, (Sequence, Iterable)) or isinstance(vals, str):
vals = [vals]

# Make sure all values are of the same data type
Expand All @@ -294,7 +294,7 @@ def extend_values(self, data):
dataset.write_data(arr, slc=np.s_[src_len: src_len + dlen])

def _check_new_value_types(self, data):
if isinstance(data, (Sequence, Iterable)) and not isinstance(data, string_types):
if isinstance(data, (Sequence, Iterable)) and not isinstance(data, str):
single_val = data[0]
else:
single_val = data
Expand Down
14 changes: 6 additions & 8 deletions nixio/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.
try:
from sys import maxint
except ImportError:
from sys import maxsize as maxint
from sys import maxsize
try:
from collections.abc import Sequence, Iterable
except ImportError:
from collections import Sequence, Iterable
from six import string_types

import numpy as np

from .container import Container, SectionContainer
from .datatype import DataType
from .entity import Entity
Expand All @@ -25,7 +23,7 @@
from . import exceptions


class S(object): # pylint: disable=invalid-name
class S: # pylint: disable=invalid-name
def __init__(self, section_type, section=None):
self.section_type = section_type
self.section = section
Expand Down Expand Up @@ -147,7 +145,7 @@ def create_property(self, name="", values_or_dtype=0, oid=None,
# Make sure all values are of the same data type
single_val = vals
if (isinstance(vals, (Sequence, Iterable)) and
not isinstance(vals, string_types)):
not isinstance(vals, str)):
single_val = vals[0]
else:
# Make sure the data will always be created with an array.
Expand Down Expand Up @@ -387,7 +385,7 @@ def find_sections(self, filtr=lambda _: True, limit=None):
:rtype: list of nixio.Section
"""
if limit is None:
limit = maxint
limit = maxsize
return finders._find_sections(self, filtr, limit)

def find_related(self, filtr=lambda _: True):
Expand Down
4 changes: 2 additions & 2 deletions nixio/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.
from sys import maxsize as maxint
from sys import maxsize

from .import exceptions
from .entity import Entity
Expand Down Expand Up @@ -173,7 +173,7 @@ def find_sources(self, filtr=lambda _: True, limit=None):
:rtype: list of nixio.Source
"""
if limit is None:
limit = maxint
limit = maxsize
return finders._find_sources(self, filtr, limit)

@property
Expand Down
3 changes: 1 addition & 2 deletions nixio/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import warnings

import numpy as np
from six import string_types

from .entity import Entity
from .source_link_container import SourceLinkContainer
Expand Down Expand Up @@ -107,7 +106,7 @@ def create_feature(self, data, link_type):
:returns: The created feature object.
:rtype: nixio.Feature
"""
if isinstance(link_type, string_types):
if isinstance(link_type, str):
link_type = link_type.lower()
link_type = LinkType(link_type)
features = self._h5group.open_group("features")
Expand Down
9 changes: 3 additions & 6 deletions nixio/test/test_data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# LICENSE file in the root of the Project.
import os
import time
from six import string_types
import sys
import unittest
import numpy as np
import nixio as nix
Expand Down Expand Up @@ -278,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 Expand Up @@ -307,8 +304,8 @@ def test_data_array_dimensions(self):
self.assertRaises(IndexError, lambda: self.array.dimensions[-4])
self.assertRaises(IndexError, lambda: self.array.dimensions[3])

assert isinstance(str(self.array.dimensions), string_types)
assert isinstance(repr(self.array.dimensions), string_types)
assert isinstance(str(self.array.dimensions), str)
assert isinstance(repr(self.array.dimensions), str)

dims = list(self.array.dimensions)
for i in range(3):
Expand Down
Loading

0 comments on commit 444aae5

Please sign in to comment.