diff dataset.py @ 269:fdce496c3b56

deprecating __getitem__[fieldname] syntax
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 04 Jun 2008 19:04:40 -0400
parents 3f1cd8897fda
children fa8abc813bd2
line wrap: on
line diff
--- a/dataset.py	Wed Jun 04 18:48:50 2008 -0400
+++ b/dataset.py	Wed Jun 04 19:04:40 2008 -0400
@@ -109,10 +109,6 @@
 
      - dataset[[i1,i2,...in]] returns a dataset with examples i1,i2,...in.
 
-     - dataset[fieldname] an iterable over the values of the field fieldname across
-     the dataset (the iterable is obtained by default by calling valuesVStack
-     over the values for individual examples).
-
      - dataset.<property> returns the value of a property associated with
      the name <property>. The following properties should be supported:
           - 'description': a textual description or name for the dataset
@@ -151,9 +147,9 @@
        - __len__ if it is not a stream
        - fieldNames
        - minibatches_nowrap (called by DataSet.minibatches())
+    For efficiency of implementation, a sub-class might also want to redefine
        - valuesHStack
        - valuesVStack
-    For efficiency of implementation, a sub-class might also want to redefine
        - hasFields
        - __getitem__ may not be feasible with some streams
        - __iter__
@@ -412,6 +408,20 @@
         """
         return DataSetFields(self,fieldnames)
 
+    def getitem_key(self, fieldname):
+        """A not-so-well thought-out place to put code that used to be in
+        getitem.
+        """
+        #removing as per discussion June 4. --JSB
+
+        i = fieldname
+        # else check for a fieldname
+        if self.hasFields(i):
+            return self.minibatches(fieldnames=[i],minibatch_size=len(self),n_batches=1,offset=0).next()[0]
+        # else we are trying to access a property of the dataset
+        assert i in self.__dict__ # else it means we are trying to access a non-existing property
+        return self.__dict__[i]
+
     def __getitem__(self,i):
         """
         dataset[i] returns the (i+1)-th example of the dataset.
@@ -460,12 +470,7 @@
                                             for fieldname,field_values
                                             in zip(self.fieldNames(),fields_values)]),
                 self.valuesVStack,self.valuesHStack)
-        # else check for a fieldname
-        if self.hasFields(i):
-            return self.minibatches(fieldnames=[i],minibatch_size=len(self),n_batches=1,offset=0).next()[0]
-        # else we are trying to access a property of the dataset
-        assert i in self.__dict__ # else it means we are trying to access a non-existing property
-        return self.__dict__[i]
+        raise TypeError(i, type(i))
 
     def valuesHStack(self,fieldnames,fieldvalues):
         """