-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Update is_sparse docstring #19983
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
Changes from all commits
10dffd1
4857b0b
7eb5dec
541fa1c
227007a
5a78a39
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 |
---|---|---|
|
@@ -150,32 +150,59 @@ def is_object_dtype(arr_or_dtype): | |
|
||
def is_sparse(arr): | ||
""" | ||
Check whether an array-like is a pandas sparse array. | ||
Check whether an array-like is a 1-D pandas sparse array. | ||
|
||
Check that the one-dimensional array-like is a pandas sparse array. | ||
Returns True if it is a pandas sparse array, not another type of | ||
sparse array. | ||
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. Personally I find this paragraph not so clear. I think something like this would be shorter and also clearer: "Return |
||
|
||
Parameters | ||
---------- | ||
arr : array-like | ||
The array-like to check. | ||
Array-like to check. | ||
|
||
Returns | ||
------- | ||
boolean : Whether or not the array-like is a pandas sparse array. | ||
bool | ||
Whether or not the array-like is a pandas sparse array. | ||
|
||
See Also | ||
-------- | ||
DataFrame.to_sparse : Convert DataFrame to a SparseDataFrame. | ||
Series.to_sparse : Convert Series to SparseSeries. | ||
datapythonista marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Series.to_dense : Return dense representation of a Series. | ||
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. Based on my comment above, I think we want to include in the see also the mentioned methods |
||
|
||
Examples | ||
-------- | ||
>>> is_sparse(np.array([1, 2, 3])) | ||
False | ||
>>> is_sparse(pd.SparseArray([1, 2, 3])) | ||
Returns `True` if the parameter is a 1-D pandas sparse array. | ||
|
||
>>> is_sparse(pd.SparseArray([0, 0, 1, 0])) | ||
True | ||
>>> is_sparse(pd.SparseSeries([1, 2, 3])) | ||
>>> is_sparse(pd.SparseSeries([0, 0, 1, 0])) | ||
True | ||
|
||
This function checks only for pandas sparse array instances, so | ||
sparse arrays from other libraries will return False. | ||
Returns `False` if the parameter is not sparse. | ||
|
||
>>> is_sparse(np.array([0, 0, 1, 0])) | ||
False | ||
>>> is_sparse(pd.Series([0, 1, 0, 0])) | ||
False | ||
|
||
Returns `False` if the parameter is not a pandas sparse array. | ||
|
||
>>> from scipy.sparse import bsr_matrix | ||
>>> is_sparse(bsr_matrix([1, 2, 3])) | ||
>>> is_sparse(bsr_matrix([0, 1, 0, 0])) | ||
False | ||
|
||
Returns `False` if the parameter has more than one dimension. | ||
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. I'd be explicit here in saying, return false if it has more than one dimension, even if it is sparse. Minor change, but I think it's a bit more clear. |
||
|
||
>>> df = pd.SparseDataFrame([389., 24., 80.5, np.nan], | ||
columns=['max_speed'], | ||
index=['falcon', 'parrot', 'lion', 'monkey']) | ||
>>> is_sparse(df) | ||
False | ||
>>> is_sparse(df.max_speed) | ||
True | ||
""" | ||
from pandas.core.arrays.sparse import SparseDtype | ||
|
||
|
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.
It will take some research, but I think it would be useful to explain what are the use cases of this function, besides what it does.