# Buggy code
def __enter__(self):
    """
    Prepare the namespace.
    """
    # Save previous __file__
    if self.ns_globals is None:
        if self.current_namespace:
            self.ns_globals, self.ns_locals = _get_globals_locals()
        else:
            ipython_shell = get_ipython()
            main_mod = ipython_shell.new_main_mod(self.filename, "__main__")
            self.ns_globals = main_mod.__dict__
            self.ns_locals = None
            # Needed to allow pickle to reference main
            if "__main__" in sys.modules:
                self._previous_main = sys.modules["__main__"]
            sys.modules["__main__"] = main_mod
            self._reset_main = True
    if "__file__" in self.ns_globals:
        self._previous_filename = self.ns_globals["__file__"]
    self.ns_globals["__file__"] = self.filename
    if self._file_code is not None and not PY2 and isinstance(self._file_code, bytes):
        try:
            self._file_code = self._file_code.decode()
        except UnicodeDecodeError:
            # Setting the cache is not supported for non utf-8 files
            self._file_code = None
    if self._file_code is not None:
        # '\n' is used instead of the native line endings. (see linecache)
        # mtime is set to None to avoid a cache update.
        linecache.cache[self.filename] = (
            len(self._file_code),
            None,
            [line + "\n" for line in self._file_code.splitlines()],
            self.filename,
        )
    return self.ns_globals, self.ns_locals


# Traceback (AttributeError)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/namespacebrowser.py", line 444, in import_data
error_message = self.shellwidget.load_data(self.filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 125, in load_data
timeout=CALL_KERNEL_TIMEOUT).load_data(filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 542, in __call__
call_dict, call_data, self._comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 114, in _get_call_return_value
call_dict, call_data, comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 420, in _get_call_return_value
return self._sync_error(reply['value'])
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 480, in _sync_error
error_wrapper.raise_error()
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 90, in raise_error
raise self.etype(self)
Exception in comms call load_data:

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/console/kernel.py", line 257, in load_data
data[new_key] = data.pop(key)

AttributeError: 'NpzFile' object has no attribute 'pop'

# Fixed code
def __enter__(self):
    """
    Prepare the namespace.
    """
    # Save previous __file__
    if self.ns_globals is None:
        if self.current_namespace:
            self.ns_globals, self.ns_locals = _get_globals_locals()
            if "__file__" in self.ns_globals:
                self._previous_filename = self.ns_globals["__file__"]
            self.ns_globals["__file__"] = self.filename
        else:
            ipython_shell = get_ipython()
            main_mod = ipython_shell.new_main_mod(self.filename, "__main__")
            self.ns_globals = main_mod.__dict__
            self.ns_locals = None
            # Needed to allow pickle to reference main
            if "__main__" in sys.modules:
                self._previous_main = sys.modules["__main__"]
            sys.modules["__main__"] = main_mod
            self._reset_main = True

    if self._file_code is not None and not PY2 and isinstance(self._file_code, bytes):
        try:
            self._file_code = self._file_code.decode()
        except UnicodeDecodeError:
            # Setting the cache is not supported for non utf-8 files
            self._file_code = None
    if self._file_code is not None:
        # '\n' is used instead of the native line endings. (see linecache)
        # mtime is set to None to avoid a cache update.
        linecache.cache[self.filename] = (
            len(self._file_code),
            None,
            [line + "\n" for line in self._file_code.splitlines()],
            self.filename,
        )
    return self.ns_globals, self.ns_locals