<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stats_per_key(self):
 """ Return statistics calculated for each key in the container. Note: The feature container has to be opened in advance. Returns: dict: A dictionary containing a DataStats object for each key. """

        self.raise_error_if_not_open()

        all_stats = {}

        for key, data in self._file.items():
            data = data[()]
            all_stats[key] = stats.DataStats(float(np.mean(data)),
                                             float(np.var(data)),
                                             np.min(data),
                                             np.max(data),
                                             data.size)

        return all_stats