Skip to content

Remove unused, avoid uses of deprecated api #22071

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 19 commits into from
Jul 31, 2018
Merged

Conversation

jbrockmendel
Copy link
Member

core.dtypes.common.is_period is confusingly named and never used. This PR gets rid of it.

The deprecated numpy API that causes zillions of warnings includes ndarray.data, so this replaces the old usage with the encouraged usage.

A bunch of tslibs.util isn't actually used in tslibs.util, so the relevant functions are moved up to _libs.util.

Docstrings for most of what's left in tslibs.util.

Simplify util._checknull by removing an unnecessary try/except.

@gfyoung gfyoung added Internals Related to non-user accessible pandas implementation Clean labels Jul 27, 2018
@gfyoung gfyoung requested a review from jreback July 27, 2018 04:38
@codecov
Copy link

codecov bot commented Jul 27, 2018

Codecov Report

Merging #22071 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22071   +/-   ##
=======================================
  Coverage   92.07%   92.07%           
=======================================
  Files         170      170           
  Lines       50690    50690           
=======================================
  Hits        46672    46672           
  Misses       4018     4018
Flag Coverage Δ
#multiple 90.48% <ø> (ø) ⬆️
#single 42.31% <ø> (ø) ⬆️

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 d30c4a0...e6fa730. Read the comment docs.

void set_array_not_contiguous(PyArrayObject* ao) {
ao->flags &= ~(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
// Numpy>=1.8-compliant equivalent to:
Copy link
Contributor

Choose a reason for hiding this comment

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

we are numpy >= 1.9! can this be simplified?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. The existing implementation uses the deprecated numpy API.

@@ -1,10 +1,18 @@
from numpy cimport ndarray
Copy link
Contributor

Choose a reason for hiding this comment

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

wait, we have a tslibs/util.pxd and a util.pxd?

Copy link
Member Author

Choose a reason for hiding this comment

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

When util.pxd was moved from src to tslibs, we added _libs/util.pxd as an alias so as to keep existing cimports

@jbrockmendel
Copy link
Member Author

we are numpy >= 1.9! can this be simplified?

An update/background on the ever-present numpy deprecation warnings. Based on conversation on the cython tracker it looks like

a) numpy more or less forgot why they did that deprecation, have no plans to follow up on it
b) this could be fixed in cython; I'll keep an eye on it but no one should hold their breath
c) if this is fixed in cython, pandas has a handful of places that uses the old API that will need to be updated (many/most of which this PR does)

AFAICT we get the deprecation warning if we do one or more of:
i) cimport numpy as cnp
ii) from numpy cimport ...
iii) cdef extern from ... any file that has an #include <numpy/...>
iii) b) unless we add to that file the lines:

#ifndef
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

iii) c) But any C file we add this to becomes off-limits for cython files that have numpy cimports (or else we get compile-time errors)


The upshot being: there are a bunch of files for which we can get rid of these warnings.

Many of the files only have numpy cimports because they need to a) call import_array in order to use util.is_integer_object, b) need int64_t, or c) need ndarray.

These can all be worked around if we get numpy cimports out of util (which this PR does)

from cpython cimport PyTypeObject

cdef extern from *:
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need this in util.pxd? (the higher level one)?

Copy link
Contributor

Choose a reason for hiding this comment

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

does this change perf?

Copy link
Member Author

Choose a reason for hiding this comment

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

does this change perf?

No.

we don't need this in util.pxd? (the higher level one)?

a) everything in this file is cimported into the other one, so it is available there. b) No, this is only used by tslibs.period.

@@ -304,34 +304,6 @@ def is_offsetlike(arr_or_obj):
return False


def is_period(arr):
Copy link
Contributor

Choose a reason for hiding this comment

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

is this not generally exposed to the user / higher level? I don't remember why we added this (and it has the wrong name)

Parameters
----------
arr : array-like
The array-like to check.
Copy link
Contributor

Choose a reason for hiding this comment

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

unfortunately I think we need to deprecate this (and remove in next version)

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this change orthogonal to this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

isn't this change orthogonal to this PR?

Sure, can be separated out. This started out as a grab-bag PR.

unfortunately I think we need to deprecate this (and remove in next version)

Darn, OK.

@jreback jreback added this to the 0.24.0 milestone Jul 30, 2018
@jreback
Copy link
Contributor

jreback commented Jul 30, 2018

the warnings in the log seem more than before on interval.pyx. but could be just me.

@jbrockmendel
Copy link
Member Author

the warnings in the log seem more than before on interval.pyx. but could be just me.

A couple PRs back that fixed a bunch of warnings, changes to interval.pyx were reverted because they caused failures on windows. So this file has been cleaned up much less than the others, might seem like more in comparison.

@jreback
Copy link
Contributor

jreback commented Jul 31, 2018

thanks!

@jreback jreback merged commit 48d4a1c into pandas-dev:master Jul 31, 2018
@jbrockmendel jbrockmendel deleted the rm branch July 31, 2018 16:00
dberenbaum pushed a commit to dberenbaum/pandas that referenced this pull request Aug 3, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants