Skip to content

Did updates to ipython_directive bork support for cython magic snippets? #4791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jan 13, 2014 · 8 comments
Closed
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Jan 13, 2014

...I wish to register a complaint.

re #4570, I'd be glad for pandas to get rid of it's copy of ipython_directive
and to that end, I rebased the pandas tweaks on the version in ipython/master (0355d3d).

I cannot however get cython magic code snippets to work with the updated version,
and I've been unable to locate other packages which do this as a sanity check.
Assuming it should work out of the box rather then as a tweak pandas added and
which I failed to carry over.

Here's an example from current pandas docs which now fails to render properly.

.. ipython:: python

   %load_ext cythonmagic


Now, let's simply copy our functions over to cython as is (the suffix
is here to distinguish between function versions):

.. ipython::

   In [2]: %%cython
      ...: def f_plain(x):
      ...:     return x * (x - 1)
      ...: def integrate_f_plain(a, b, N):
      ...:     s = 0
      ...:     dx = (b - a) / N
      ...:     for i in range(N):
      ...:         s += f_plain(a + i * dx)
      ...:     return s * dx
      ...:

.. note::

  If you're having trouble pasting the above into your ipython, you may need
  to be using bleeding edge ipython for paste to play well with cell magics.


.. ipython:: python

   %timeit df.apply(lambda x: integrate_f_plain(x['a'], x['b'], x['N']), axis=1)

Is it my fault or is there an issue with the new version?

cc @takluyver, @jorisvandenbossche

@jorisvandenbossche
Copy link
Contributor

@y-p And you also did port the changes done to support the cython code in the docs in pandas when it was added to the docs? (see pandas-dev/pandas@2d64fb5)

@ghost
Copy link
Author

ghost commented Jan 13, 2014

bingo.

@ghost ghost closed this as completed Jan 13, 2014
@takluyver
Copy link
Member

What do you see when you do that?

@takluyver
Copy link
Member

Oh, you solved it. Great. :-)

@ghost
Copy link
Author

ghost commented Jan 13, 2014

There was a very anonymous looking whitspace handling code added which
I overlooked. Apperently that makes cython magics work.

pandas-dev/pandas#5925 contains a clean diff against
the new version of ipython_directive, if ipython picks up the missing bits
we'll be very glad to close ranks with you.

@cpcloud
Copy link

cpcloud commented Jan 15, 2014

Hey guys just wanted to chime in here, I made those not-so-anonymous changes to pandas ipython_directive.py. The prompt was adding an extra space to the input lines that needed to be removed (otherwise its invalid Cython code), and then added back in so that it appears in the user facing documentation.

@ghost
Copy link
Author

ghost commented Jan 15, 2014

Looks like this is in fact a long standing bug in ipython_directive that was only fixed recently
in pandas. PR coming up. reopening for now.

btw, anon in that nothing about the diff suggsted a link to cython, would a comment have killed you? ;)

@ghost
Copy link
Author

ghost commented Jan 27, 2014

closed by #4803

@ghost ghost closed this as completed Jan 27, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants