Skip to content

Support for OO Optimization #21093

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

Merged
merged 21 commits into from
May 30, 2018
Merged

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented May 16, 2018

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comment, looks good to me

@@ -53,6 +55,15 @@ def test_xarray(df):
assert df.to_xarray() is not None


def test_xarray_oo_optimizable():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove the "xarray" here, as it is generally useful to ensure this, not only for xarray

@codecov
Copy link

codecov bot commented May 16, 2018

Codecov Report

Merging #21093 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21093      +/-   ##
==========================================
- Coverage   91.84%   91.84%   -0.01%     
==========================================
  Files         153      153              
  Lines       49538    49505      -33     
==========================================
- Hits        45499    45466      -33     
  Misses       4039     4039
Flag Coverage Δ
#multiple 90.23% <100%> (-0.01%) ⬇️
#single 41.88% <100%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/util/_decorators.py 81.96% <100%> (-0.3%) ⬇️
pandas/tseries/offsets.py 97% <100%> (ø) ⬆️
pandas/io/formats/printing.py 89.38% <0%> (-3.71%) ⬇️
pandas/core/tools/datetimes.py 84.43% <0%> (-0.55%) ⬇️
pandas/core/indexes/datetimelike.py 96.79% <0%> (-0.1%) ⬇️
pandas/core/arrays/categorical.py 95.67% <0%> (-0.01%) ⬇️
pandas/core/frame.py 97.22% <0%> (ø) ⬆️
pandas/core/indexes/base.py 96.68% <0%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c85ab08...75dbaad. Read the comment docs.

@@ -1090,12 +1090,15 @@ def apply(self, other):


class CustomBusinessMonthEnd(_CustomBusinessMonth):
__doc__ = _CustomBusinessMonth.__doc__.replace('[BEGIN/END]', 'end')
if _CustomBusinessMonth.__doc__:
__doc__ = _CustomBusinessMonth.__doc__.replace('[BEGIN/END]', 'end')
_prefix = 'CBM'


class CustomBusinessMonthBegin(_CustomBusinessMonth):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to do this with @subsitution and template this. We dont' use this pattern anywhere and might be confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense - I'll take a look and repush

@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label May 16, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also pls add a whatsnew 0.23.1 ok

@jreback jreback added this to the 0.23.1 milestone May 17, 2018
@@ -53,6 +55,11 @@ def test_xarray(df):
assert df.to_xarray() is not None


def test_oo_optimizable():
# GH 21071
subprocess.check_call(["python", "-OO", "-c", "import pandas"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does pandas import all modules at import pandas? If not, maybe this will be helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd do we want to go this way to also check some submodules?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a look - if it's not a lot of effort I suppose it doesn't hurt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been messing around with this for a bit but AFAICT it keeps getting choked up when trying to import modules containing optional dependencies (ex: pandas.io.s3). I can't think of a simple way to configure the test so that it can differentiate intentional ImportErrors as a result of missing dependencies.

For now I'm going to revert to just working with the top level import - can open a separate issue if we wanted this to work recursively

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if it turns out difficult, on problem in starting with the basic test (which already tests the large majority of our API)

Name of function to deprecate
alternative : str
Name of function to use instead
name : func
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am overlooking something I didn't see where this decorator was being used, but it seems like there is a mismatch between what was documented and the types it actually accepts (at least looking at alternative).

To make this work with substitution I took the liberty of assuming these arguments should functions and not strings whenever this decorator gets used

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am overlooking something I didn't see where this decorator was being used,

It's not used a lot, but at least it is used for argmin/argmax and for scatter_matrix (it is not used there as a decorator, so I searched for "deprecate("

@WillAyd
Copy link
Member Author

WillAyd commented May 22, 2018

The failures here are the result of __doc__ not being mutable for classes in Python27. I did some research on alternatives and there don't appear to be any that are that simple.

I suppose this explains why the Substitution / Appender system wasn't used in the first place for the CustomBusinessMonth classes and I don't see it used on any other classes within the code base (just methods).

@jreback would you be OK with keeping the CustomBusinessMonthStart and CustomBusinessMonthBegin classes as is?

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -94,3 +94,8 @@ Categorical
^^^^^^^^^^^

-

Other
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move the tab completion entry here as well (its just below Bug Fixes)


%(msg)s

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why, but it seems this does not give the correct docstring.
Can you check that pd.Series.argmin? still gives the deprecation warning at the top? (I checked out this branch and didn't see it, while on master it is there)

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@@ -1090,12 +1090,17 @@ def apply(self, other):


class CustomBusinessMonthEnd(_CustomBusinessMonth):
__doc__ = _CustomBusinessMonth.__doc__.replace('[BEGIN/END]', 'end')
# TODO: Replace condition with Subsitution after dropping Py27 support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we could standarize these todos so can find later, maybe TODO(py27), I think we are doing similar to EA t

@WillAyd
Copy link
Member Author

WillAyd commented May 30, 2018

AppVeyor failure is the random ResourceWarning that's been popping up which I was hoping would be fixed through #21105 but apparently was not. I don't believe its related to this change

@jreback
Copy link
Contributor

jreback commented May 30, 2018

ok this looks fine. @jorisvandenbossche do you have any comments.

@jorisvandenbossche jorisvandenbossche merged commit 4cbbcc6 into pandas-dev:master May 30, 2018
@jorisvandenbossche
Copy link
Member

Thanks!

@WillAyd WillAyd deleted the oo-import branch May 30, 2018 22:03
jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Jun 8, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jun 9, 2018
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas is no longer importable with -OO optimization
4 participants