Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
cache ctable.dtype
Browse files Browse the repository at this point in the history
Among others, this allow improving the performance of custom implementations of
the outflavor abstraction layer.
  • Loading branch information
ARF committed May 6, 2015
1 parent 73da749 commit 883f196
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bcolz/ctable.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def cparams(self):
@property
def dtype(self):
"The data type of this object (numpy dtype)."
if self._dtype:
return self._dtype

names, cols = self.names, self.cols
l = []
for name in names:
Expand All @@ -150,7 +153,8 @@ def dtype(self):
t = (name, col.dtype) if col.ndim == 1 else \
(name, (col.dtype, col.shape[1:]))
l.append(t)
return np.dtype(l)
self._dtype = np.dtype(l)
return self._dtype

@property
def names(self):
Expand Down Expand Up @@ -222,6 +226,8 @@ def __init__(self, columns=None, names=None, **kwargs):
# Attach the attrs to this object
self.attrs = attrs.attrs(self.rootdir, self.mode, _new=_new)

# Trigger update of dtype cache
self._dtype = None
# Cache a structured array of len 1 for ctable[int] acceleration
self._arr1 = np.empty(shape=(1,), dtype=self.dtype)

Expand Down Expand Up @@ -487,6 +493,8 @@ def addcol(self, newcol, name=None, pos=None, move=False, **kwargs):

# Insert the column
self.cols.insert(name, pos, newcol)
# Trigger update of dtype cache
self._dtype = None
# Update _arr1
self._arr1 = np.empty(shape=(1,), dtype=self.dtype)

Expand Down Expand Up @@ -540,6 +548,8 @@ def delcol(self, name=None, pos=None, keep=False):
if not keep:
col.purge()

# Trigger update of dtype cache
self._dtype = None
# Update _arr1
self._arr1 = np.empty(shape=(1,), dtype=self.dtype)

Expand Down

0 comments on commit 883f196

Please sign in to comment.