CLN/DEPR: Final panel removal
State: closed

- [ ] closes #25632
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:

Comments:
That looked easy ;)
https://travis-ci.org/pandas-dev/pandas/jobs/551916327

xarray is explicity referencing Panel. not sure if if this is actually failing on the current one though.
So we will need to keep something like 

```
class Panel:

    def __init__(self, *args, **kwargs):
        raise ImportError("pandas.Panel is removed")
```

in core/panel.py and still import that in the main pandas namespace to avoid breaking released version of statsmodels and xarray.
Brief glance at the xarray source this is used for introspection so not sure a dummy class is that useful. Perhaps something more cleanly handled downstream? cc @shoyer 


statsmodels is doing the same type of checking ?

cc @jbrockmendel 
>statsmodels is doing the same type of checking ?

Yes.  Opened https://github.com/statsmodels/statsmodels/pull/5892 to remove it.
I can fix this prior to the next xarray bug fix release

On Fri, Jun 28, 2019 at 2:46 PM jbrockmendel <notifications@github.com>
wrote:

> statsmodels is doing the same type of checking ?
>
> Yes. Opened statsmodels/statsmodels#5892
> <https://github.com/statsmodels/statsmodels/pull/5892> to remove it.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/27101?email_source=notifications&email_token=AAJJFVTTGYVMVBEINENYJQLP42BBXA5CNFSM4H4HN7FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY3HTBI#issuecomment-506886533>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAJJFVXFKORSKIFQSMW6WBDP42BBXANCNFSM4H4HN7FA>
> .
>

For what it's worth, this is probably an indication that the deprecation notice for Panel was not entirely effective, because it could still be used only for type checks without an error. In the future it would probably make sense to use module level `__getattr__` when deprecating classes.
> For what it's worth, this is probably an indication that the deprecation notice for Panel was not entirely effective, because it could still be used only for type checks without an error. In the future it would probably make sense to use module level `__getattr__` when deprecating classes.

@shoyer well that's *very* hard with < 3.7 (we did actually have some machinery to do this but blew it away a while back as it was complex) and not worth the effort IMHO.


I would "be nice" for now and don't knowingly break other projects. As @shoyer said, it is hard to catch this as the specific use case does not result in a warning message (so there will probably be other projects as well). If we want to release a RC next week, I think it is better if that RC does not break importing statsmodels or xarray.

Or, @shoyer, do you plan to do a xarray bugfix release soonish?

Keeping a dummy class is not that hard (only a couple of lines of code). For Python 3.7 we could maybe actually use the getattribute trick (if it is possible to do that depending on the python version)
Something like this seems to work (at least on Python 3.7):

```patch
diff --git a/pandas/__init__.py b/pandas/__init__.py
index eafb89c52..d1d4cf678 100644
--- a/pandas/__init__.py
+++ b/pandas/__init__.py
@@ -158,3 +158,18 @@ Here are just a few of the things that pandas does well:
     conversion, moving window statistics, moving window linear regressions,
     date shifting and lagging, etc.
 """
+
+if pandas.compat.PY37:
+    def __getattr__(name):
+        if name == 'Panel':
+            import warnings
+            warnings.warn(
+                "The Panel class is removed from pandas. Accessing it from the "
+                "top-level namespace will also be removed in the next version",
+                FutureWarning, stacklevel=2)
+            return None
+        raise AttributeError(
+            "module 'pandas' has no attribute {}".format(name))
+else:
+    class Panel:
+        pass
```
@WillAyd In order to get this merged, are you ok with adding something like the above? (https://github.com/pandas-dev/pandas/pull/27101#issuecomment-507052023)
I would prefer not to add something like that since we have been targeting removal on 0.25 for a while and we still then wouldn't be removing it. 
To be clear, I don't propose to keep the 1000+ lines of panel code. We *are* removing the actual Panel class. I only propose to add a few lines to give a more gracious deprecation for a use case we have not been raising a warning for.
> I would prefer not to add something like that since we have been targeting removal on 0.25 for a while and we still then wouldn't be removing it.

Agreed.  Especially if it is mainly xarray and statsmodels we're worried about, we can help them get quick bugfix releases out and have this over Once And For All.
I think a compatibility shim like https://github.com/pandas-dev/pandas/pull/27101#issuecomment-507052023 is good to have for a bit.

@WillAyd do you have time to do that? If not, do you mind if I do it sometime tonight?
Even if xarray issues a bug fix release in the next week (which is quite
likely), there are still going to be combinations of pandas with
statsmodels/xarray that don't even import. This sort of strict version
compatibility requirements is best avoided if possible, and in this case it
looks like it would be pretty easy/painless to avoid.

On Tue, Jul 2, 2019 at 1:14 PM Tom Augspurger <notifications@github.com>
wrote:

> I think a compatibility shim like #27101 (comment)
> <https://github.com/pandas-dev/pandas/pull/27101#issuecomment-507052023>
> is good to have for a bit.
>
> @WillAyd <https://github.com/WillAyd> do you have time to do that? If
> not, do you mind if I do it sometime tonight?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/27101?email_source=notifications&email_token=AAJJFVRXWJVPGS4ORMCELQ3P5OZJ5A5CNFSM4H4HN7FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZCNMPY#issuecomment-507827775>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAJJFVUI3ZLLGGHMMWHVFQDP5OZJ5ANCNFSM4H4HN7FA>
> .
>

yeah i think we need this shim.
Sure will probably get to this tonight

Sent from my iPhone

> On Jul 2, 2019, at 4:54 PM, Jeff Reback <notifications@github.com> wrote:
> 
> yeah i think we need this shim.
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.

@WillAyd I pushed some compat code; let's see.
@jreback I think we should do the getattr check on Python 3.7 as I showed above in https://github.com/pandas-dev/pandas/pull/27101#issuecomment-507052023. 
That actually gives a deprecation warning for the use case that we are keeping a dummy class for (only if you are using py 3.7, but that is at least something).
> @jreback I think we should do the getattr check on Python 3.7 as I showed above in [#27101 (comment)](https://github.com/pandas-dev/pandas/pull/27101#issuecomment-507052023).
> That actually gives a deprecation warning for the use case that we are keeping a dummy class for (only if you are using py 3.7, but that is at least something).

@jorisvandenbossche ok sure
Hello @WillAyd! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:















There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2019-07-03 15:44:44 UTC
Thanks Jeff! Traveling back west today so feel free to move forward on this without me if a blocker. Otherwise can pick up later this evening
@TomAugspurger I think this needs a conditional in pandas/tests/api/tests_api.py where if < py37 then add to the class list (deprecated), otherwise its not there. I can do later today unless you want to push a patch.
I can take care of it.

On Wed, Jul 3, 2019 at 6:35 AM Jeff Reback <notifications@github.com> wrote:

> @TomAugspurger <https://github.com/TomAugspurger> I think this needs a
> condition in pandas/tests/api/tests_api.py where if < py37 then add to the
> class list (deprecated), otherwise its not there. I can do later today
> unless you want to push a patch.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/27101?email_source=notifications&email_token=AAKAOIWNQP4AEA4O7ZSD433P5SFILA5CNFSM4H4HN7FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZEFF6A#issuecomment-508056312>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAKAOIRJCVNFZ4CEPNMLVCTP5SFILANCNFSM4H4HN7FA>
> .
>

```
doc/source/whatsnew/v0.15.0.rst(734,6): error E999: SyntaxError: invalid syntax
doc/source/whatsnew/v0.11.0.rst(392,12): error E999: SyntaxError: invalid syntax
Bash exited with code '1'.
```
Fixing now.
@jreback the CI failure is unrelated (the categorical ASV we fixed in the other PR).

Should be good to go.