-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
DEPR: Series ndarray properties (strides, data, base, itemsize, flags) #20721
DEPR: Series ndarray properties (strides, data, base, itemsize, flags) #20721
Conversation
pandas/core/base.py
Outdated
@@ -737,11 +737,17 @@ def item(self): | |||
@property | |||
def data(self): | |||
""" return the data pointer of the underlying data """ | |||
warnings.warn("Series/Index.data is deprecated and will be " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to make the warning messages a bit more dynamic with something like:
"{obj}.data is deprecated...".format(obj=type(self).__name__)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you (somehow I was the docstring mindset thinking we needed to adapt this upon class definition, but of course this can be done dynamically on run time :-))
Hello @jorisvandenbossche! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on April 24, 2018 at 12:42 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #20721 +/- ##
==========================================
- Coverage 91.85% 91.84% -0.01%
==========================================
Files 153 153
Lines 49308 49316 +8
==========================================
+ Hits 45290 45296 +6
- Misses 4018 4020 +2
Continue to review full report at Codecov.
|
f10dd3f
to
11182b1
Compare
@@ -328,7 +328,7 @@ def test_series_agg_multi_pure_python(): | |||
'F': np.random.randn(11)}) | |||
|
|||
def bad(x): | |||
assert (len(x.base) > 0) | |||
assert (len(x.values.base) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure what the purpose of this assert actually is (was introduced in 71e9046)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls run all tests and see if any warnings comes up
pandas/core/indexes/datetimelike.py
Outdated
""" return the base object if the memory of the underlying data is | ||
shared | ||
""" | ||
# override deprecated property in IndexOpsMixin, as we still need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your explanation doesn't make sense, we are deprecating these no? you need to change the way its accessed in the code to remove the warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explanation perfectly makes sense, but you don't like the way I solved it I suppose (I agree it is not the nicest, but I was thinking that this would only be temporarily until DatetimeTZBlock is an ExtensionBlock).
To fix the usage itself, .base
is used in two placed:
Block.is_view
: this I can override inDatetimeTzBlock
to checkself.values.values.base
concatenate_join_units
:pandas/pandas/core/internals.py
Line 5544 in ede11af
if copy and concat_values.base is not None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point is this method should not exist (as you are ddeprecateding), and would rather have you fix the usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, I agree with that. Do you have a suggestion for the second case? (inside concatenate_join_units
) In #20745 I need to touch the same code, and checked if the values have a base
attribute, but that also feels hacky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, see my comment there, only check base if its an ndarray
pandas/core/algorithms.py
Outdated
@@ -1491,6 +1491,8 @@ def take_nd(arr, indexer, axis=0, out=None, fill_value=np.nan, mask_info=None, | |||
if is_sparse(arr): | |||
arr = arr.get_values() | |||
|
|||
arr = np.array(arr, copy=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.asarray
slightly more idiomatic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes (for some reason I wanted the copy=False
keyword, but for asarray
that is of course just the default behaviour)
pandas/core/indexes/datetimelike.py
Outdated
""" return the base object if the memory of the underlying data is | ||
shared | ||
""" | ||
# override deprecated property in IndexOpsMixin, as we still need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point is this method should not exist (as you are ddeprecateding), and would rather have you fix the usage
can you update |
Now that #20745 is merged, updated this. |
@jorisvandenbossche a couple new warnings I think: https://travis-ci.org/pandas-dev/pandas/jobs/369977719#L2762
Can you see if they're easy to fix? |
lgtm, other than @TomAugspurger comments. |
lgtm. modulo any warnings fixes. note that I just pushed a CI fix for lint (on other PR) |
@@ -548,6 +548,9 @@ def _deepcopy_if_needed(self, orig, copy=False): | |||
""" | |||
if copy: | |||
# Retrieve the "base objects", i.e. the original memory allocations | |||
if not isinstance(orig, np.ndarray): | |||
# orig is a DatetimeIndex | |||
orig = orig.values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback This special case is because we sometimes construct DatetimeIndex objects where the _data
attribute still is a DatetimeIndex in itself.
To me this seems like something we should not do? (it doesn't hurt, but there is also no reason to have it I think, so better always store the ndarray to be consistent?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should never do that
how did this come up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just opened an issue about it: #20810
It came up from fixing the warnings in the tests. The above case, where orig
is not always a ndarray (hence my special case if
statement), triggered it, because orig
always comes from a _data
attribute, and so I expected it to always be a ndarray.
Thanks @jorisvandenbossche |
I was doing scipy.fftpack.fft over a series and it showed error as What should I use instead? And how to overcome it? |
git diff upstream/master -u -- "*.py" | flake8 --diff