-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
chore(ci): fix numpy type errors and revert #22610 #22782
Changes from 5 commits
d6fd474
c3431e3
5a6b49f
f302f9f
54b0f3f
5bdbdac
65724f3
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 |
---|---|---|
|
@@ -17,9 +17,9 @@ | |
[metadata] | ||
name = Superset | ||
summary = a data exploration platform | ||
description-file = README.md | ||
description_file = README.md | ||
author = Apache Superset Dev | ||
author-email = [email protected] | ||
author_email = [email protected] | ||
license = Apache License, Version 2.0 | ||
|
||
[files] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import numpy as np | ||
import pandas as pd | ||
import pyarrow as pa | ||
from numpy.typing import NDArray | ||
|
||
from superset.db_engine_specs import BaseEngineSpec | ||
from superset.superset_typing import DbapiDescription, DbapiResult, ResultSetColumnType | ||
|
@@ -62,16 +63,16 @@ def stringify(obj: Any) -> str: | |
return json.dumps(obj, default=utils.json_iso_dttm_ser) | ||
|
||
|
||
def stringify_values(array: np.ndarray) -> np.ndarray: | ||
def stringify_values(array: NDArray[Any]) -> NDArray[Any]: | ||
result = np.copy(array) | ||
|
||
with np.nditer(result, flags=["refs_ok"], op_flags=["readwrite"]) as it: | ||
with np.nditer(result, flags=["refs_ok"], op_flags=[["readwrite"]]) as it: | ||
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. Wow, this actually caught an incorrect type! |
||
for obj in it: | ||
if pd.isna(obj): | ||
if na_obj := pd.isna(obj): | ||
# pandas <NA> type cannot be converted to string | ||
obj[pd.isna(obj)] = None | ||
obj[na_obj] = None # type: ignore | ||
else: | ||
obj[...] = stringify(obj) | ||
obj[...] = stringify(obj) # type: ignore | ||
|
||
return result | ||
|
||
|
@@ -106,7 +107,7 @@ def __init__( # pylint: disable=too-many-locals | |
pa_data: List[pa.Array] = [] | ||
deduped_cursor_desc: List[Tuple[Any, ...]] = [] | ||
numpy_dtype: List[Tuple[str, ...]] = [] | ||
stringified_arr: np.ndarray | ||
stringified_arr: NDArray[Any] | ||
|
||
if cursor_description: | ||
# get deduped list of column names | ||
|
@@ -208,7 +209,7 @@ def convert_table_to_df(table: pa.Table) -> pd.DataFrame: | |
return table.to_pandas(integer_object_nulls=True, timestamp_as_object=True) | ||
|
||
@staticmethod | ||
def first_nonempty(items: List[Any]) -> Any: | ||
def first_nonempty(items: NDArray[Any]) -> Any: | ||
return next((i for i in items if i), None) | ||
|
||
def is_temporal(self, db_type_str: Optional[str]) -> bool: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,10 @@ def boxplot( | |
""" | ||
|
||
def quartile1(series: Series) -> float: | ||
return np.nanpercentile(series, 25, interpolation="midpoint") | ||
return np.nanpercentile(series, 25, interpolation="midpoint") # type: ignore | ||
|
||
def quartile3(series: Series) -> float: | ||
return np.nanpercentile(series, 75, interpolation="midpoint") | ||
return np.nanpercentile(series, 75, interpolation="midpoint") # type: ignore | ||
|
||
if whisker_type == PostProcessingBoxplotWhiskerType.TUKEY: | ||
|
||
|
@@ -99,8 +99,8 @@ def whisker_low(series: Series) -> float: | |
return np.nanpercentile(series, low) | ||
|
||
else: | ||
whisker_high = np.max | ||
whisker_low = np.min | ||
whisker_high = np.max # type: ignore | ||
whisker_low = np.min # type: ignore | ||
|
||
def outliers(series: Series) -> Set[float]: | ||
above = series[series > whisker_high(series)] | ||
|
@@ -126,7 +126,7 @@ def outliers(series: Series) -> Set[float]: | |
# nanpercentile needs numeric values, otherwise the isnan function | ||
# that's used in the underlying function will fail | ||
for column in metrics: | ||
if df.dtypes[column] == np.object: | ||
if df.dtypes[column] == np.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. Nowadays >>> import numpy as np
>>> np.object
<stdin>:1: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
<class 'object'> I'm opting for |
||
df[column] = to_numeric(df[column], errors="coerce") | ||
|
||
return aggregate(df, groupby=groupby, aggregates=aggregates) |
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.
Bycatch; noticed this was being emitted by
pylint
: