Repository navigation
GH-55767: [Python][Annotations] Narrow inherited return types with generic private base classes (_PandasConvertible, _Tabular) - #55792
Conversation
|
@AlenkaF @jorisvandenbossche @rok: Ready for review! Here are two nice clean examples where making private base classes ( |
rok
left a comment
There was a problem hiding this comment.
This looks good to me. I'll ask Joris to check as well.
|
The change in the stub tests is super nice =) I would propose though to fist get the basic stubs (minimal overloads, no generics) in as we still have modules missing (compute, scalar, ...). This way we will be safe to get the basic setup in for the next release and still have time to introduce generics later? Plus, they might be useful elsewhere too. |
|
Completely agree on focusing on basic stubs and avoiding all public generics! This PR wouldn't make any public class generic (like |
|
Yes, agreed with @tadeja and I think we can go ahead here and merge this. Ensuring the typing is correct regarding something returning Array vs ChunkedArray is I think something basic we should get right from the start, while something returning Int32Array vs Int64Array is much more advanced. So if we don't go this way, I think we should right now add overloads to ensure those return types are correct. And at that point this seems a nice solution to avoid adding a bunch overloads to narrow down the return type |
|
|
||
| class _PandasConvertible(_Weakrefable): | ||
| # to_pandas() arrays return Series, tables return DataFrame | ||
| _PandasT = TypeVar("_PandasT", pd.Series[Any], pd.DataFrame) |
There was a problem hiding this comment.
Is there a reason we are using pd.Series[Any] instead of pd.Series? (from a typing perspective, is there actually a difference?)
|
Aha, ok, thanks for the background @tadeja , helps a lot! I thought we are removing generics in full to ease first batch of reviews and get smaller changes, so didn't think private vs public made any difference, sorry. Happy you pushed this forward then 👍 |
Rationale for this change
Close #55767. Methods inherited from private
_PandasConvertibleand_Tabularreturned unions on every subclass.What changes are included in this PR?
_PandasConvertibleis generic over itsto_pandas()result_Tabularis generic over its column typeAre these changes tested?
Yes, and new
assert_typetest cases added as well.Are there any user-facing changes?
Yes, type checkers now infer narrower return types for these methods.
Was AI used for this PR?
PR code and description written by:
Reviewed before submission by: