Skip to content

Conversation

@jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jbrockmendel generally LGTM.

# error: Incompatible return value type (got "Tuple[ndarray, ndarray]",
# expected "Tuple[ndarray, ExtensionArray]")
return codes, uniques # type: ignore[return-value]
uniques_ea = self._from_factorized(uniques, self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the return type annotation is missing for _from_factorized so this resolves to Any

maybe could change here but the variable name would still need to changed anyway so could also be follow-up since _quantile_ea_compat would also need fixing.

if len(self.arrays) == 0:
arr = np.empty(self.shape, dtype=float)
return arr.transpose() if transpose else arr
farr = np.empty(self.shape, dtype=float)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm guessing the f represents float? Rather than guessing can you rename this, maybe "float_arr" or "empty" or "empty_arr"


while on the subject, I've never guessed or seen anything to give a clue as to what tipo is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while on the subject, I've never guessed or seen anything to give a clue as to what tipo is?

i think its DtypeObj; no idea on why the name was chosen

@final
@property
def array(self):
def array(self) -> ArrayLike:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while here can you add error: "SingleDataManager" has no attribute "arrays"; maybe "array" comment above the ignore below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

# _SupportsDtype, str, Tuple[Any, int], Tuple[Any, Union[int,
# Sequence[int]]], List[Any], _DtypeDict, Tuple[Any, Any]]"
result = np.empty(x.size, dtype=dtype) # type: ignore[arg-type]
# x and y are both ndarrays -> common_dtype is np.dtype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should overload find_common_type. could add a # TODO

fill_value = 0
# error: Non-overlapping equality check (left operand type: "dtype[Any]", right
# operand type: "Type[bool]")
elif dtype == bool: # type: ignore[comparison-overlap]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a false positive (maybe from numpy types)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.bool_ does not inherit from bool: https://numpy.org/doc/stable/reference/arrays.scalars.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is Non-overlapping equality check.... The numpy types should allow a check with a type. either bool, np.bool_ and str, object or any other type. Doing the equality check does not raise a type error, but should always return bool.

import numpy as np dtype = np.dtype("bool") print(dtype) print(dtype == bool) print(dtype == np.bool_) print(dtype == "bool") print(dtype == object) 

gives

bool True True True False 

In the numpy type annotations for 1.21.3, dtype.__eq__ is not defined, but looks like this is fixed on master. numpy/numpy#20184

https://github.com/numpy/numpy/blob/8eb6555711888f0ab5594a2bd82d230ba33a3d7c/numpy/__init__.pyi#L876-L880

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what's the suggested action here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what you've done is fine. but we could also leave these ignores for now.

Once we are checking with the latest numpy types we could maybe revert all the changes that have been made to-date to get round this. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

# no NaNs - can just concatenate
result = cat_safe(all_cols, sep)

out: Index | Series
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add this as the return type of the function signature.

result = Index( # type: ignore[assignment]
result, dtype=object, name=self._orig.name
)
out = Index(result, dtype=object, name=self._orig.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe could just return here and no need for the variable type annotation.

# error: Non-overlapping equality check (left operand type: "dtype[Any]", right
# operand type: "Type[signedinteger[Any]]")
if dtype == np.int8: # type: ignore[comparison-overlap]
if dtype.type == np.int8:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still work with is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think so, will check

@simonjayhawkins simonjayhawkins added Clean Typing type annotations, mypy/pyright type checking labels Nov 4, 2021
@simonjayhawkins simonjayhawkins added this to the 1.4 milestone Nov 4, 2021
@simonjayhawkins simonjayhawkins merged commit 0769386 into pandas-dev:master Nov 5, 2021
@simonjayhawkins
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the fixmes7 branch November 5, 2021 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Clean Typing type annotations, mypy/pyright type checking

3 participants