-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TYP: overload lib.maybe_convert_objects #41166
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 1 commit
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 |
---|---|---|
|
@@ -420,10 +420,8 @@ def fillna(self, value=None, method=None, limit=None): | |
if mask.any(): | ||
if method is not None: | ||
func = missing.get_fill_func(method) | ||
# error: Argument 1 to "to_numpy" of "ArrowStringArray" has incompatible | ||
# type "Type[object]"; expected "Union[str, dtype[Any], None]" | ||
new_values, _ = func( | ||
self.to_numpy(object), # type: ignore[arg-type] | ||
self.to_numpy("object"), | ||
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 is an unrelated change to the scope (from the PR title) of this PR. The mypy error is a false positive, no need to change code. will be fixed in #41185 but I guess nbd (other than merge conflicts) |
||
limit=limit, | ||
mask=mask, | ||
) | ||
|
@@ -740,11 +738,7 @@ def _str_map(self, f, na_value=None, dtype: Dtype | None = None): | |
if not na_value_is_na: | ||
mask[:] = False | ||
|
||
# error: Argument 1 to "IntegerArray" has incompatible type | ||
# "Union[ExtensionArray, ndarray]"; expected "ndarray" | ||
# error: Argument 1 to "BooleanArray" has incompatible type | ||
# "Union[ExtensionArray, ndarray]"; expected "ndarray" | ||
return constructor(result, mask) # type: ignore[arg-type] | ||
return constructor(result, mask) | ||
|
||
elif is_string_dtype(dtype) and not is_object_dtype(dtype): | ||
# i.e. StringDtype | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,9 +61,12 @@ def _str_map(self, f, na_value=None, dtype: Optional[Dtype] = None): | |
na_value = self._str_na_value | ||
|
||
if not len(self): | ||
# error: Argument 1 to "ndarray" has incompatible type "int"; | ||
# expected "Sequence[int]" | ||
return np.ndarray(0, dtype=dtype) # type: ignore[arg-type] | ||
# error: Argument "dtype" to "array" has incompatible type | ||
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected | ||
# "Union[dtype[Any], None, type, _SupportsDType, str, | ||
# Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any], | ||
# _DTypeDict, Tuple[Any, Any]]]" | ||
return np.array([], dtype=dtype) # type: ignore[arg-type] | ||
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'm confused about why import numpy as np
from pandas._typing import Dtype, Optional
def foo(dtype: Optional[Dtype] = None):
if dtype is None:
dtype = np.dtype("object")
return (np.array([], dtype=type)) then 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. no idea. i think this edit is unrelated to most of the rest; 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. The
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'm embarrassed, thanks! 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. so this looks like there maybe an actual bug here. As part of the ArrowStringArray work, I have been parameterising existing tests on object dtype arrays with StringArray and ArrowStringArray and this has maybe uncovered some latent bugs with StringArray. I think OK to leave this ignore as a 'fix later' and out of scope here. |
||
|
||
arr = np.asarray(self, dtype=object) | ||
mask = isna(arr) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,9 +252,7 @@ def _convert_and_box_cache( | |
from pandas import Series | ||
|
||
result = Series(arg).map(cache_array) | ||
# error: Argument 1 to "_box_as_indexlike" has incompatible type "Series"; expected | ||
# "Union[ExtensionArray, ndarray]" | ||
return _box_as_indexlike(result, utc=None, name=name) # type: ignore[arg-type] | ||
return _box_as_indexlike(result._values, utc=None, name=name) | ||
|
||
|
||
def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> Index: | ||
|
@@ -368,13 +366,11 @@ def _convert_listlike_datetimes( | |
arg, _ = maybe_convert_dtype(arg, copy=False) | ||
except TypeError: | ||
if errors == "coerce": | ||
result = np.array(["NaT"], dtype="datetime64[ns]").repeat(len(arg)) | ||
return DatetimeIndex(result, name=name) | ||
npvalues = np.array(["NaT"], dtype="datetime64[ns]").repeat(len(arg)) | ||
return DatetimeIndex(npvalues, name=name) | ||
elif errors == "ignore": | ||
# error: Incompatible types in assignment (expression has type | ||
# "Index", variable has type "ExtensionArray") | ||
result = Index(arg, name=name) # type: ignore[assignment] | ||
return result | ||
idx = Index(arg, name=name) | ||
return idx | ||
raise | ||
|
||
arg = ensure_object(arg) | ||
|
@@ -393,18 +389,14 @@ def _convert_listlike_datetimes( | |
require_iso8601 = not infer_datetime_format | ||
format = None | ||
|
||
# error: Incompatible types in assignment (expression has type "None", variable has | ||
# type "ExtensionArray") | ||
result = None # type: ignore[assignment] | ||
result = None | ||
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 this needed? The |
||
|
||
if format is not None: | ||
# error: Incompatible types in assignment (expression has type | ||
# "Optional[Index]", variable has type "ndarray") | ||
result = _to_datetime_with_format( # type: ignore[assignment] | ||
res = _to_datetime_with_format( | ||
arg, orig_arg, name, tz, format, exact, errors, infer_datetime_format | ||
) | ||
if result is not None: | ||
return result | ||
if res is not None: | ||
return res | ||
|
||
if result is None: | ||
assert format is None or infer_datetime_format | ||
|
@@ -509,13 +501,11 @@ def _to_datetime_with_format( | |
|
||
# fallback | ||
if result is None: | ||
# error: Incompatible types in assignment (expression has type | ||
# "Optional[Index]", variable has type "Optional[ndarray]") | ||
result = _array_strptime_with_fallback( # type: ignore[assignment] | ||
res = _array_strptime_with_fallback( | ||
arg, name, tz, fmt, exact, errors, infer_datetime_format | ||
) | ||
if result is not None: | ||
return result | ||
if res is not None: | ||
return res | ||
|
||
except ValueError as e: | ||
# Fallback to try to convert datetime objects if timezone-aware | ||
|
Uh oh!
There was an error while loading. Please reload this page.