-
-
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: deprecate SparseArray.values #26421
Changes from all commits
1865863
1018049
781fcd0
979a3fe
e3737c0
09d5122
baeda5f
9f61b73
1f9e5fb
fb3aebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ from numpy cimport (ndarray, | |
cnp.import_array() | ||
|
||
cimport pandas._libs.util as util | ||
from pandas._libs.lib import maybe_convert_objects | ||
from pandas._libs.lib import maybe_convert_objects, values_from_object | ||
|
||
|
||
cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt): | ||
|
@@ -28,6 +28,14 @@ cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt): | |
return np.empty(size, dtype='O') | ||
|
||
|
||
cdef bint _is_sparse_array(object obj): | ||
# TODO can be removed one SparseArray.values is removed (GH26421) | ||
if hasattr(obj, '_subtyp'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this idiom should be getattr |
||
if obj._subtyp == 'sparse_array': | ||
return True | ||
return False | ||
|
||
|
||
cdef class Reducer: | ||
""" | ||
Performs generic reduction operation on a C or Fortran-contiguous ndarray | ||
|
@@ -146,7 +154,8 @@ cdef class Reducer: | |
else: | ||
res = self.f(chunk) | ||
|
||
if hasattr(res, 'values') and util.is_array(res.values): | ||
if (not _is_sparse_array(res) and hasattr(res, 'values') | ||
and util.is_array(res.values)): | ||
res = res.values | ||
if i == 0: | ||
result = _get_result_array(res, | ||
|
@@ -432,7 +441,8 @@ cdef class SeriesGrouper: | |
cdef inline _extract_result(object res): | ||
""" extract the result object, it might be a 0-dim ndarray | ||
or a len-1 0-dim, or a scalar """ | ||
if hasattr(res, 'values') and util.is_array(res.values): | ||
if (not _is_sparse_array(res) and hasattr(res, 'values') | ||
and util.is_array(res.values)): | ||
res = res.values | ||
if not np.isscalar(res): | ||
if util.is_array(res): | ||
|
@@ -635,8 +645,7 @@ def reduce(arr, f, axis=0, dummy=None, labels=None): | |
raise Exception('Cannot use shortcut') | ||
|
||
# pass as an ndarray | ||
if hasattr(labels, 'values'): | ||
labels = labels.values | ||
labels = values_from_object(labels) | ||
|
||
reducer = Reducer(arr, f, axis=axis, dummy=dummy, labels=labels) | ||
return reducer.get_result() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2272,10 +2272,10 @@ def _cast_sparse_series_op(left, right, opname): | |
# TODO: This should be moved to the array? | ||
if is_integer_dtype(left) and is_integer_dtype(right): | ||
# series coerces to float64 if result should have NaN/inf | ||
if opname in ('floordiv', 'mod') and (right.values == 0).any(): | ||
if opname in ('floordiv', 'mod') and (right.to_dense() == 0).any(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we not be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both are equivalent (although |
||
left = left.astype(SparseDtype(np.float64, left.fill_value)) | ||
right = right.astype(SparseDtype(np.float64, right.fill_value)) | ||
elif opname in ('rfloordiv', 'rmod') and (left.values == 0).any(): | ||
elif opname in ('rfloordiv', 'rmod') and (left.to_dense() == 0).any(): | ||
left = left.astype(SparseDtype(np.float64, left.fill_value)) | ||
right = right.astype(SparseDtype(np.float64, right.fill_value)) | ||
|
||
|
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.
Would this be better-suited for
pandas._libs.util
? Or keep here since this is the only file using it and it's temporary?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, exactly for those reasons (It's only used here, and should be removed again once we get rid of this deprecation), I would keep it here (it's not mean to be a general utility)
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.
this is not the right location not should be in util
your argument is not correct ; just because we eventually will remove it does not mean it should. it be with similar code