-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: @doc - base.py & indexing.py #31970
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 8 commits
06a5d9e
9a4abae
e580a96
ede988c
41a7552
6cd8082
1534dad
703f7a6
a1b0e0b
5077ab0
8ea6e1b
8e320ce
1ee2cf7
7bf242e
61e87af
224cec8
e01e108
48cfcda
20f96f2
76ed611
95a86ee
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,6 +15,7 @@ | |
Substitution, | ||
cache_readonly, | ||
deprecate_kwarg, | ||
doc, | ||
) | ||
from pandas.util._validators import validate_bool_kwarg, validate_fillna_kwargs | ||
|
||
|
@@ -51,7 +52,7 @@ | |
_extension_array_shared_docs, | ||
try_cast_to_ea, | ||
) | ||
from pandas.core.base import NoNewAttributesMixin, PandasObject, _shared_docs | ||
from pandas.core.base import IndexOpsMixin, NoNewAttributesMixin, PandasObject | ||
import pandas.core.common as com | ||
from pandas.core.construction import array, extract_array, sanitize_array | ||
from pandas.core.indexers import check_array_indexer, deprecate_ndim_indexing | ||
|
@@ -1352,8 +1353,7 @@ def memory_usage(self, deep=False): | |
""" | ||
return self._codes.nbytes + self.dtype.categories.memory_usage(deep=deep) | ||
|
||
@Substitution(klass="Categorical") | ||
@Appender(_shared_docs["searchsorted"]) | ||
@doc(IndexOpsMixin.searchsorted, klass="Categorical") | ||
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 this be inheriting from core.arrays.base.ExtensionArray instead? Also I can't see this docstring in the published docs. 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 agree with this comment here - this seems strange to use |
||
def searchsorted(self, value, side="left", sorter=None): | ||
# searchsorted is very performance sensitive. By converting codes | ||
# to same dtype as self.codes, we get much faster performance. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from pandas._libs.tslibs import timezones | ||
from pandas.compat.numpy import function as nv | ||
from pandas.errors import AbstractMethodError | ||
from pandas.util._decorators import Appender, cache_readonly | ||
from pandas.util._decorators import Appender, cache_readonly, doc | ||
|
||
from pandas.core.dtypes.common import ( | ||
ensure_int64, | ||
|
@@ -31,7 +31,7 @@ | |
from pandas.core import algorithms | ||
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray | ||
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin | ||
from pandas.core.base import _shared_docs | ||
from pandas.core.base import IndexOpsMixin | ||
import pandas.core.indexes.base as ibase | ||
from pandas.core.indexes.base import Index, _index_shared_docs | ||
from pandas.core.indexes.extension import ( | ||
|
@@ -206,7 +206,7 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs): | |
self, indices, axis, allow_fill, fill_value, **kwargs | ||
) | ||
|
||
@Appender(_shared_docs["searchsorted"]) | ||
@doc(IndexOpsMixin.searchsorted, klass="Datetime-like Index") | ||
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. Same comment - this is very confusing 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. Hi @WillAyd, I agree with you and @ simonjayhawkins here. It might be confusing. However, the original docstring is not extended from the base class. It seems like the original code obscures the problem because it does not explicitly indicate the source of the docstring. I try to keep it as it is but use It looks like we all agree this docstring template will confuse other developers, but do you feel needed to fix this issue in this PR? If so, what will be your suggestion? One option that comes in my mind will be using the docstring from the base class, and modify them to fit in this case. I was trying to avoid that because it will change the original docstring relations, and I am not sure if we did this on purpose. Just to be clarified, I am very willing to make the additional change to solve this confusion. I just don't know what will be the best way of doing that. One more thing, I have a comment related to this. You might also be interested. 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. Is there a more suitable location for the docstring then? Importing the IndexOpsMixin here is strange 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 think this should be addressed in a follow up. It's here in 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.
For me, I feel this situation might be caused by they are sharing the same interface, but don't have a common ancestor. If we have an interface declaration, I would say putting docstring there would be a good choice. However, Python as a dynamic programming language, don't have to declare the interface. Now, I don't have a good solution in mind, but I would like to look for it and see if we can find somewhere that makes more sense. |
||
def searchsorted(self, value, side="left", sorter=None): | ||
if isinstance(value, str): | ||
raise TypeError( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,7 +275,8 @@ def wrapper(*args, **kwargs) -> Callable: | |
elif hasattr(arg, "_docstr_template"): | ||
templates.append(arg._docstr_template) # type: ignore | ||
elif arg.__doc__: | ||
templates.append(arg.__doc__) | ||
doc_tmp = arg.__doc__.replace("{", "{{").replace("}", "}}") | ||
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 don't understand this, do you mind explaining why is this needed? 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. Hi, a short quick answer: You must already know this, but just want to clarify this again so that helps others catch up: Back to our case: Please take the changes in this file as an example: @doc(IndexingMixin.iloc)
class _iLocIndexer(_LocationIndexer): I am not sure if I explain the reason clear enough, please feel free to come with follow up questions. 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. Sorry, I still don't get it. I see these cases: Not using
Using
I guess what this solves is taking a docstring from a non-decorated function, and use it with the decorator, converting it from the first case to the second. But this feels a bit hacky, and I'm not sure if it would make more sense to apply And if we need to keep this implementation, we need to add comments so a reader can understand what's going on, and what these 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.
Yes, exactly! Thanks for helping me explain this. That is want I try to say.
That make sense to me. I would like to give it a try.
I agree with you here. I would like to try the idea above first, and a backup solution might be using string template to avoid this case. 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.
Hi @datapythonista, I have modified the |
||
templates.append(doc_tmp) | ||
|
||
wrapper._docstr_template = "".join(dedent(t) for t in templates) # type: ignore | ||
wrapper.__doc__ = wrapper._docstr_template.format(**kwargs) # type: ignore | ||
|
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.
I believe I am in the minority on this view and don't want to be overly difficult, but can you refactor the
IndexOpsMixin
as a pre-cursor to this, or leave this module separate from the rest of changes (which look good btw)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, that is a good idea. I would convert this back to using
_shared_docs
. This PR is already too large, and I should really put them separately.