internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ipython/ipython

Issue:
Notebook: Long delay before closing/server stop on Windows
I'm on Windows with ipython 2.4.0

The console says "Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).". But doing so takes over a minute on my machine to actually exit! Just measured and it was 102 seconds.

It's faster to just kill python.exe. Which is ugly and can't be the expected behavior. This is not new for me, but I couldn't find related issues, so what's up with that?



Discussion:
If you have a lot of kernels running with a lot of things in memory, it might take a while to clean them all up, but 100 seconds seems extreme. How many kernels did it need to shut down?

If the problem is with a large number of kernels, it should be much better in IPython 3. IPython 2 sends a shutdown message to each kernel and waits for it to exit before moving on to the next. IPython 3 asks all the kernels to shut down and then waits for them (#5764).

Only one, and a fast machine - that's the thing!

And is this the case even if you haven't run anything in that kernel?

@minrk, any ideas? I know how much you enjoy debugging process issues on Windows ;-)

Yes, even with "ipython notebook" and immediately closing after.

If you do that, it should have _no_ kernels to shut down, which is even more mystifying. A kernel is only started when you click open a notebook file.

The inner loop is actually uninterruptible on Windows. It will catch the interrupt the first time an event is processed, so if your browser is open it should exit promptly. We can add a no-op callback at 5-10 second intervals to put an upper limit on the delay.

We should probably add that callback.

Perhaps we should also use the tornado asyncio wrapper on Windows when it's available. I would expect that that is not uninterruptible.

> Perhaps we should also use the tornado asyncio wrapper on Windows

I don't think we can. It would need to use the same uninterruptible zmq poll as the inner loop. Plus, tornado can only be used with the SelectorEventLoop. It is not compatible with the Proactor one that may have better behavior.


Resolving patch:
diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py
--- a/IPython/html/notebookapp.py
+++ b/IPython/html/notebookapp.py
@@ -1061,6 +1061,11 @@ def start(self):
                 threading.Thread(target=b).start()
         
         self.io_loop = ioloop.IOLoop.current()
+        if sys.platform.startswith('win'):
+            # add no-op to wake every 5s
+            # to handle signals that may be ignored by the inner loop
+            pc = ioloop.PeriodicCallback(lambda : None, 5000)
+            pc.start()
         try:
             self.io_loop.start()
         except KeyboardInterrupt:


Test patch:
Repository: ipython/ipython

Issue:
Parameterized traitlets and default value validation
When using a List traitlet with validated elements, the default value of the elements is validated, like in this example:

``` Python
from IPython.utils.traitlets import *

class Bar():
    pass

class Foo(HasTraits):
    bars = List(Instance(Bar, allow_none=False))

foo = Foo()
```

which yields a `TraitError` because the default value, None, is invalid. 

A fix would be to do `bars = List(Instance(Bar, tuple(), allow_none=False))`, i.e. to create a  default value. But somehow, I think that there should not be a need to instantiate a default value that is never going to be used!

@minrk should the default value be validated when the traitlet is to be used in a "template" trait like List? 



Discussion:
Btw, it seems that this validation was not happening with `IPython 2.2`. 

Hm,  it seems like the default value shouldn't be generated at all, but there may be too many things going on right now for me to have an accurate picture in my head. I will try to think about this more carefully in the morning. Thanks for catching it.


Resolving patch:
diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py
--- a/IPython/utils/traitlets.py
+++ b/IPython/utils/traitlets.py
@@ -1461,8 +1461,8 @@ def validate_elements(self, obj, value):
     def instance_init(self, obj):
         if isinstance(self._trait, TraitType):
             self._trait.this_class = self.this_class
-        if hasattr(self._trait, 'instance_init'):
-            self._trait.instance_init(obj)
+        if hasattr(self._trait, '_resolve_classes'):
+            self._trait._resolve_classes()
         super(Container, self).instance_init(obj)
 
 
@@ -1631,6 +1631,14 @@ def validate_elements(self, obj, value):
                 validated.append(v)
         return tuple(validated)
 
+    def instance_init(self, obj):
+        for trait in self._traits:
+            if isinstance(trait, TraitType):
+                trait.this_class = self.this_class
+            if hasattr(trait, '_resolve_classes'):
+                trait._resolve_classes()
+        super(Container, self).instance_init(obj)
+
 
 class Dict(Instance):
     """An instance of a Python dict."""


Test patch:
diff --git a/IPython/utils/tests/test_traitlets.py b/IPython/utils/tests/test_traitlets.py
--- a/IPython/utils/tests/test_traitlets.py
+++ b/IPython/utils/tests/test_traitlets.py
@@ -972,6 +972,19 @@ def coerce(self, value):
 class Foo(object):
     pass
 
+class NoneInstanceListTrait(HasTraits):
+    
+    value = List(Instance(Foo, allow_none=False))
+
+class TestNoneInstanceList(TraitTestBase):
+
+    obj = NoneInstanceListTrait()
+
+    _default_value = []
+    _good_values = [[Foo(), Foo()], []]
+    _bad_values = [[None], [Foo(), None]]
+
+
 class InstanceListTrait(HasTraits):
 
     value = List(Instance(__name__+'.Foo'))
Repository: ipython/ipython

Issue:
Alias mpl nbagg 
Talking to @danielballan today he pointed out that nbagg, while accurate and making lots of sense to mpl developers, is not the clearest our most user friendly name.  

Would it make sense to provide an alias in the mpl related ipython magic to a more suitable name? Would it be possible to get that alias in for 3.0 at this late date?



Discussion:
Possibly. Any thoughts on what to call it?
On 12 Feb 2015 21:33, "Thomas A Caswell" notifications@github.com wrote:

> Talking to @danielballan https://github.com/danielballan today he
> pointed out that nbagg, while accurate and making lots of sense to mpl
> developers, is not the clearest our most user friendly name.
> 
> Would it make sense to provide an alias in the mpl related ipython magic
> to a more suitable name? Would it be possible to get that alias in for 3.0
> at this late date?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/ipython/ipython/issues/7774.

`%matplotlib notebook` ?

+1 for  `%matplotlib notebook`

Since we have `qt` for `QtAgg`, it makes sense to me for `notebook` to be `nbagg` (`nb` would be a bit terse, I think). Any objections? @fperez or @ellisonbg?

+1 on `notebook`. This is small enough that it's OK this late in the game: b/c I suspect it will get broad usage and 3.x will be a long-lived series, I'd rather have it in now.

I just saw that nbagg support was included in 2.4. Should we keep `nbagg` as an alias for compatibility, backport `notebook` to 2.4.2, just switch to `notebook`, or something else? 2.4 has been out for two weeks.

+1

Sent from my iPhone

> On Feb 13, 2015, at 10:34 AM, Min RK notifications@github.com wrote:
> 
> Since we have qt for QtAgg, it makes sense to me for notebook to be nbagg (nb would be a bit terse, I think). Any objections? @fperez or @ellisonbg?
> 
> —
> Reply to this email directly or view it on GitHub.

I'd leave nbagg for compatibility and just add notebook as an alias.

Sounds good.


Resolving patch:
diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py
--- a/IPython/core/pylabtools.py
+++ b/IPython/core/pylabtools.py
@@ -22,6 +22,7 @@
             'qt5': 'Qt5Agg',
             'osx': 'MacOSX',
             'nbagg': 'nbAgg',
+            'notebook': 'nbAgg',
             'inline' : 'module://IPython.kernel.zmq.pylab.backend_inline'}
 
 # We also need a reverse backends2guis mapping that will properly choose which
diff --git a/IPython/kernel/zmq/eventloops.py b/IPython/kernel/zmq/eventloops.py
--- a/IPython/kernel/zmq/eventloops.py
+++ b/IPython/kernel/zmq/eventloops.py
@@ -40,6 +40,7 @@ def process_stream_events():
 loop_map = {
     'inline': None,
     'nbagg': None,
+    'notebook': None,
     None : None,
 }
 


Test patch:
Repository: ipython/ipython

Issue:
Default DOMWidget Padding should be 0px, and Button styling issue
@jdfreder

![padding](https://cloud.githubusercontent.com/assets/2397974/6379572/53fb8cfc-bd01-11e4-9786-f350566688b0.png)



Discussion:

Resolving patch:
diff --git a/IPython/html/widgets/interaction.py b/IPython/html/widgets/interaction.py
--- a/IPython/html/widgets/interaction.py
+++ b/IPython/html/widgets/interaction.py
@@ -181,7 +181,7 @@ def interactive(__interact_f, **kwargs):
     co = kwargs.pop('clear_output', True)
     manual = kwargs.pop('__manual', False)
     kwargs_widgets = []
-    container = Box()
+    container = Box(_dom_classes=['widget-interact'])
     container.result = None
     container.args = []
     container.kwargs = dict()
diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py
--- a/IPython/html/widgets/widget.py
+++ b/IPython/html/widgets/widget.py
@@ -435,7 +435,7 @@ class DOMWidget(Widget):
     width = CUnicode(sync=True)
     height = CUnicode(sync=True)
     # A default padding of 2.5 px makes the widgets look nice when displayed inline.
-    padding = CUnicode("2.5px", sync=True)
+    padding = CUnicode(sync=True)
     margin = CUnicode(sync=True)
 
     color = Unicode(sync=True)


Test patch:
Repository: ipython/ipython

Issue:
Cache-Control being set twice for no_cache_paths
Whether browsers pick the first or last instance of a repeat header is ill defined. Some will pick the first (Firefox) and wind up caching custom.js practically forever (or until notebook server restart) and others will pick the latter and behave as intended.

![screen shot 2015-03-03 at 10 41 59 pm](https://cloud.githubusercontent.com/assets/153745/6477895/c9990c92-c1f6-11e4-91b5-2a4e52ce7b26.png)

PR with the fix in a moment.



Discussion:

Resolving patch:
diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py
--- a/IPython/html/base/handlers.py
+++ b/IPython/html/base/handlers.py
@@ -404,7 +404,7 @@ def set_headers(self):
         # disable browser caching, rely on 304 replies for savings
         if "v" not in self.request.arguments or \
                 any(self.request.path.startswith(path) for path in self.no_cache_paths):
-            self.add_header("Cache-Control", "no-cache")
+            self.set_header("Cache-Control", "no-cache")
     
     def initialize(self, path, default_filename=None, no_cache_paths=None):
         self.no_cache_paths = no_cache_paths or []


Test patch:
Repository: ipython/ipython

Issue:
cannot export to notebook with magic command in IPython 3.0.0
I was trying to export command history into a notebook with `%notebook -e $notebook_file`, and got the following error:
<pre><code>/Users/w/python-venv/2.7/lib/python2.7/site-packages/IPython/core/magics/basic.pyc in notebook(self, s)
    605                 cells.append(v4.new_code_cell(
    606                     execution_count=execution_count,
--> 607                     source=source
    608                 ))
    609             nb = v4.new_notebook(cells=cells)

NameError: global name 'source' is not defined</pre></code>

Had a quick look in the file `IPython/core/magics/basic.py`, and I guess the line `source=source` should be replaced by `source=input`?

Here is the output of `python -c "import IPython; print(IPython.sys_info())"` on my system:
<pre><code>{'commit_hash': u'f75fda4',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/Users/w/python-venv/2.7/lib/python2.7/site-packages/IPython',
 'ipython_version': '3.0.0',
 'os_name': 'posix',
 'platform': 'Darwin-14.1.0-x86_64-i386-64bit',
 'sys_executable': '/Users/w/python-venv/2.7/bin/python',
 'sys_platform': 'darwin',
 'sys_version': '2.7.6 (default, Sep  9 2014, 15:04:36) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]'}</pre></code>



Discussion:

Resolving patch:
diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py
--- a/IPython/core/magics/basic.py
+++ b/IPython/core/magics/basic.py
@@ -601,7 +601,9 @@ def notebook(self, s):
         if args.export:
             cells = []
             hist = list(self.shell.history_manager.get_range())
-            for session, execution_count, input in hist[:-1]:
+            if(len(hist)<=1):
+                raise ValueError('History is empty, cannot export')
+            for session, execution_count, source in hist[:-1]:
                 cells.append(v4.new_code_cell(
                     execution_count=execution_count,
                     source=source


Test patch:
diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py
--- a/IPython/core/tests/test_magic.py
+++ b/IPython/core/tests/test_magic.py
@@ -623,9 +623,13 @@ def test_extension():
 @skipIf(dec.module_not_available('IPython.nbformat'), 'nbformat not importable')
 class NotebookExportMagicTests(TestCase):
     def test_notebook_export_json(self):
+        _ip = get_ipython()
+        _ip.history_manager.reset()   # Clear any existing history.
+        cmds = [u"a=1", u"def b():\n  return a**2", u"print('noël, été', b())"]
+        for i, cmd in enumerate(cmds, start=1):
+            _ip.history_manager.store_inputs(i, cmd)
         with TemporaryDirectory() as td:
             outfile = os.path.join(td, "nb.ipynb")
-            _ip.ex(py3compat.u_format(u"u = {u}'héllo'"))
             _ip.magic("notebook -e %s" % outfile)
Repository: ipython/ipython

Issue:
Non-string argument to json.loads in the magic menu of the QtConsole
I get the following error whenever I click on "Show Magics" in the Magic menu of the IPython QtConsole (IPython 3.1.0-dev on Python 2.7.6).

<pre><code>
Traceback (most recent call last):
  File "/Users/rosborn/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/qt/base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "/Users/rosborn/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/qt/console/ipython_widget.py", line 188, in _handle_execute_reply
    super(IPythonWidget, self)._handle_execute_reply(msg)
  File "/Users/rosborn/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/qt/console/frontend_widget.py", line 452, in _handle_execute_reply
    self._handle_exec_callback(msg)
  File "/Users/rosborn/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/qt/console/frontend_widget.py", line 417, in _handle_exec_callback
    self._callback_dict.pop(expression)(user_exp[expression])
  File "/Users/rosborn/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/qt/console/mainwindow.py", line 741, in _handle_data
    self.magic_helper.populate_magic_helper(data)
  File "/Users/rosborn/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/qt/console/magic_helper.py", line 135, in populate_magic_helper
    data['data'].get('application/json', {})
  File "/Users/rosborn/Applications/Canopy.app/appdata/canopy-1.5.2.2785.macosx-x86_64/Canopy.app/Contents/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/Users/rosborn/Applications/Canopy.app/appdata/canopy-1.5.2.2785.macosx-x86_64/Canopy.app/Contents/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
</code></pre>


According to the json documentation, `json.loads` is meant to have a string argument, but `mdict = json.loads(display_data['data'].get('application/json', {}))` passes a dictionary. Should there be a call to json.dumps first? I'm puzzled because I think this code has been in there for a while, but I only just started getting these errors.



Discussion:

Resolving patch:
diff --git a/IPython/qt/console/magic_helper.py b/IPython/qt/console/magic_helper.py
--- a/IPython/qt/console/magic_helper.py
+++ b/IPython/qt/console/magic_helper.py
@@ -131,9 +131,7 @@ def populate_magic_helper(self, data):
         self.search_class.clear()
         self.search_list.clear()
                 
-        self.data = json.loads(
-            data['data'].get('application/json', {})
-        )
+        self.data = data['data'].get('application/json', {})
         
         self.search_class.addItem('All Magics', 'any')
         classes = set()


Test patch:
Repository: ipython/ipython

Issue:
`_log_format_changed()` missing 3 required positional arguments
In `IPython.config.application`, the `_log_datefmt_changed` handler calls `_log_format_changed` but does not pass it the required arguments. My guess would be that this is the correct implementation:

```
def _log_datefmt_changed(self, name, old, new):
    self._log_format_changed(name, self.log_format, self.log_format)
```

However I am not really sure what the `name` parameter is for, so I might be wrong.



Discussion:
I think the name should just be `'log_format'` - it's there so you can use one function as the changed callback for several different traitlets, IIRC.

Ok, cool. I'll make a PR then.

Thanks!

The signature for traitlet changed callbacks is a bit odd, but we can't really change it. They can accept any of:
- No arguments
- `name`
- `name, new`
- `name, old, new`

I think most of the time, `new` is the only parameter actually used.


Resolving patch:
diff --git a/IPython/config/application.py b/IPython/config/application.py
--- a/IPython/config/application.py
+++ b/IPython/config/application.py
@@ -159,7 +159,7 @@ def _log_level_changed(self, name, old, new):
         help="The date format used by logging formatters for %(asctime)s"
     )
     def _log_datefmt_changed(self, name, old, new):
-        self._log_format_changed()
+        self._log_format_changed('log_format', self.log_format, self.log_format)
     
     log_format = Unicode("[%(name)s]%(highlevel)s %(message)s", config=True,
         help="The Logging format template",


Test patch:
diff --git a/IPython/config/tests/test_application.py b/IPython/config/tests/test_application.py
--- a/IPython/config/tests/test_application.py
+++ b/IPython/config/tests/test_application.py
@@ -80,6 +80,7 @@ def test_log(self):
         # trigger reconstruction of the log formatter
         app.log.handlers = [handler]
         app.log_format = "%(message)s"
+        app.log_datefmt = "%Y-%m-%d %H:%M"
         app.log.info("hello")
         nt.assert_in("hello", stream.getvalue())
Repository: ipython/ipython

Issue:
Qtconsole Unicode repr mojibake
IPython 3.1.0 Qtconsole under Python 2.7.9 (win32):

``` python
In [1]: import pandas
In [2]: pandas.DataFrame({'spam': [u'sp\xe4m']})
Out[2]: 
   spam
0  spÃ¤m
```

As opposed to the plain IPython shell:

``` python
In [2]: pandas.DataFrame({'spam': [u'sp\xe4m']})
Out[2]:
   spam
0  späm
```



Discussion:
I thought this problem was fixed precisely in 3.1.


Resolving patch:
diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py
--- a/IPython/lib/pretty.py
+++ b/IPython/lib/pretty.py
@@ -112,6 +112,7 @@ def _repr_pretty_(self, p, cycle):
 from collections import deque
 
 from IPython.utils.py3compat import PY3, cast_unicode
+from IPython.utils.encoding import get_stream_enc
 
 from io import StringIO
 
@@ -140,7 +141,8 @@ def _safe_getattr(obj, attr, default=None):
     class CUnicodeIO(StringIO):
         """StringIO that casts str to unicode on Python 2"""
         def write(self, text):
-            return super(CUnicodeIO, self).write(cast_unicode(text))
+            return super(CUnicodeIO, self).write(
+                cast_unicode(text, encoding=get_stream_enc(sys.stdout)))
 
 
 def pretty(obj, verbose=False, max_width=79, newline='\n', max_seq_length=MAX_SEQ_LENGTH):


Test patch:
Repository: ipython/ipython

Issue:
Comm messages aren't handled in ExecutePreprocessor
The `ExecutePreprocessor` in nbconvert doesn't properly handle comm messages, resulting in a bunch of errors like this when using widgets or the `nbagg` matplotlib backend:

```
unhandled iopub msg: comm_open
unhandled iopub msg: comm_msg
unhandled iopub msg: comm_msg
...
```

The fix is pretty trivial; it just involves adding another if clause to the if statement that checks the message type:

```
elif msg_type.startswith('comm'):
    continue
```

I feel like this is something that should probably be fixed in 3.x, but since nbconvert has already been moved I'm not sure where I should submit the fix. Should I submit it against master, and whoever backports it will handle making the same changes on 3.x? Should I submit two PRs? Should I just wait until the split is done?



Discussion:
@jhamrick Backporting patches actually works fine across renames There's a bit in our backport script that gets in the way, but I've already applied a patch having commented that out, and it was okay.

After the code has actually left the repo, it will probably be a two PR process.

@minrk Ok, I'll submit a PR against master then and we'll see how that goes.


Resolving patch:
diff --git a/jupyter_nbconvert/preprocessors/execute.py b/jupyter_nbconvert/preprocessors/execute.py
--- a/jupyter_nbconvert/preprocessors/execute.py
+++ b/jupyter_nbconvert/preprocessors/execute.py
@@ -130,6 +130,8 @@ def run_cell(self, cell):
             elif msg_type == 'clear_output':
                 outs = []
                 continue
+            elif msg_type.startswith('comm'):
+                continue
 
             try:
                 out = output_from_msg(msg)


Test patch: