Skip to content
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: Support Python 3.10 and bump pandas 1.4 and pyarrow 6 #21002

Merged
merged 13 commits into from
Aug 17, 2022
Merged
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ Commits to `master` trigger a rebuild and redeploy of the documentation site. Su
Make sure your machine meets the [OS dependencies](https://superset.apache.org/docs/installation/installing-superset-from-scratch#os-dependencies) before following these steps.
You also need to install MySQL or [MariaDB](https://mariadb.com/downloads).

Ensure that you are using Python version 3.8 or 3.9, then proceed with:
Ensure that you are using Python version 3.8, 3.9 or 3.10, then proceed with:

```bash
# Create a virtual environment and activate it (recommended)
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.
#

# Python version installed; we need 3.8-3.9
PYTHON=`command -v python3.9 || command -v python3.8`
# Python version installed; we need 3.8-3.10
PYTHON=`command -v python3.10 || command -v python3.9 || command -v python3.8`

.PHONY: install superset venv pre-commit

Expand Down Expand Up @@ -70,7 +70,7 @@ update-js:

venv:
# Create a virtual environment and activate it (recommended)
if ! [ -x "${PYTHON}" ]; then echo "You need Python 3.8 or 3.9 installed"; exit 1; fi
if ! [ -x "${PYTHON}" ]; then echo "You need Python 3.8, 3.9 or 3.10 installed"; exit 1; fi
test -d venv || ${PYTHON} -m venv venv # setup a python3 virtualenv
. venv/bin/activate

Expand Down
1 change: 1 addition & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ assists people when migrating to a new version.

- [20606](https://github.com/apache/superset/pull/20606): When user clicks on chart title or "Edit chart" button in Dashboard page, Explore opens in the same tab. Clicking while holding cmd/ctrl opens Explore in a new tab. To bring back the old behaviour (always opening Explore in a new tab), flip feature flag `DASHBOARD_EDIT_CHART_IN_NEW_TAB` to `True`.
- [20799](https://github.com/apache/superset/pull/20799): Presto and Trino engine will now display tracking URL for running queries in SQL Lab. If for some reason you don't want to show the tracking URL (for example, when your data warehouse hasn't enable access for to Presto or Trino UI), update `TRACKING_URL_TRANSFORMER` in `config.py` to return `None`.
- [21002](https://github.com/apache/superset/pull/21002): Support Python 3.10 and bump pandas 1.4 and pyarrow 6.

### Breaking Changes

Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ packaging==21.3
# via
# bleach
# deprecation
pandas==1.3.4
pandas==1.4.3
# via apache-superset
parsedatetime==2.6
# via apache-superset
Expand All @@ -197,7 +197,7 @@ prison==0.2.1
# via flask-appbuilder
prompt-toolkit==3.0.28
# via click-repl
pyarrow==5.0.0
pyarrow==6.0.1
# via apache-superset
pycparser==2.20
# via cffi
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ def get_git_sha() -> str:
"markdown>=3.0",
"msgpack>=1.0.0, <1.1",
"numpy==1.22.1",
"pandas>=1.3.0, <1.4",
"pandas>=1.4.3, <1.5",
"parsedatetime",
"pgsanity",
"polyline",
"pyparsing>=3.0.6, <4",
"python-dateutil",
"python-dotenv",
"python-geohash",
"pyarrow>=5.0.0, <6.0",
"pyarrow>=6.0.1, <7",
"pyyaml>=5.4",
"PyJWT>=2.4.0, <3.0",
"redis",
Expand Down Expand Up @@ -182,5 +182,6 @@ def get_git_sha() -> str:
classifiers=[
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
)
2 changes: 1 addition & 1 deletion superset/charts/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def apply_post_process(
if query["result_format"] == ChartDataResultFormat.JSON:
df = pd.DataFrame.from_dict(query["data"])
elif query["result_format"] == ChartDataResultFormat.CSV:
df = pd.read_csv(StringIO(query["data"]))
df = pd.read_csv(StringIO(query["data"]), engine="pyarrow")
EugeneTorap marked this conversation as resolved.
Show resolved Hide resolved

processed_df = post_processor(df, form_data, datasource)

Expand Down
2 changes: 1 addition & 1 deletion superset/datasets/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def load_data(
data = request.urlopen(data_uri) # pylint: disable=consider-using-with
if data_uri.endswith(".gz"):
data = gzip.open(data)
df = pd.read_csv(data, encoding="utf-8")
df = pd.read_csv(data, encoding="utf-8", engine="pyarrow")
dtype = get_dtype(df, dataset)

# convert temporal columns
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/bart_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_bart_lines(only_metadata: bool = False, force: bool = False) -> None:
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
content = get_example_data("bart-lines.json.gz")
content = get_example_data("bart-lines.json.gz", make_bytes=True)
EugeneTorap marked this conversation as resolved.
Show resolved Hide resolved
df = pd.read_json(content, encoding="latin-1")
df["path_json"] = df.path.map(json.dumps)
df["polyline"] = df.path.map(polyline.encode)
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/birth_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def gen_filter(


def load_data(tbl_name: str, database: Database, sample: bool = False) -> None:
pdf = pd.read_json(get_example_data("birth_names2.json.gz"))
pdf = pd.read_json(get_example_data("birth_names2.json.gz", make_bytes=True))
# TODO(bkyryliuk): move load examples data into the pytest fixture
if database.backend == "presto":
pdf.ds = pd.to_datetime(pdf.ds, unit="ms")
Expand Down
4 changes: 2 additions & 2 deletions superset/examples/countries.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ This data was downloaded from the
Here's the script that was used to massage the data:

DIR = ""
df_country = pd.read_csv(DIR + '/HNP_Country.csv')
df_country = pd.read_csv(DIR + '/HNP_Country.csv', engine="pyarrow")
df_country.columns = ['country_code'] + list(df_country.columns[1:])
df_country = df_country[['country_code', 'Region']]
df_country.columns = ['country_code', 'region']

df = pd.read_csv(DIR + '/HNP_Data.csv')
df = pd.read_csv(DIR + '/HNP_Data.csv', engine="pyarrow")
del df['Unnamed: 60']
df.columns = ['country_name', 'country_code'] + list(df.columns[2:])
ndf = df.merge(df_country, how='inner')
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/country_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def load_country_map_data(only_metadata: bool = False, force: bool = False) -> N
csv_bytes = get_example_data(
"birth_france_data_for_country_map.csv", is_gzip=False, make_bytes=True
)
data = pd.read_csv(csv_bytes, encoding="utf-8")
data = pd.read_csv(csv_bytes, encoding="utf-8", engine="pyarrow")
data["dttm"] = datetime.datetime.now().date()
data.to_sql(
tbl_name,
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_energy(
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
data = get_example_data("energy.json.gz")
data = get_example_data("energy.json.gz", make_bytes=True)
pdf = pd.read_json(data)
pdf = pdf.head(100) if sample else pdf
pdf.to_sql(
Expand Down
4 changes: 2 additions & 2 deletions superset/examples/flights.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def load_flights(only_metadata: bool = False, force: bool = False) -> None:

if not only_metadata and (not table_exists or force):
data = get_example_data("flight_data.csv.gz", make_bytes=True)
pdf = pd.read_csv(data, encoding="latin-1")
pdf = pd.read_csv(data, encoding="latin-1", engine="pyarrow")

# Loading airports info to join and get lat/long
airports_bytes = get_example_data("airports.csv.gz", make_bytes=True)
airports = pd.read_csv(airports_bytes, encoding="latin-1")
airports = pd.read_csv(airports_bytes, encoding="latin-1", engine="pyarrow")
airports = airports.set_index("IATA_CODE")

pdf[ # pylint: disable=unsupported-assignment-operation,useless-suppression
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/long_lat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_long_lat_data(only_metadata: bool = False, force: bool = False) -> None

if not only_metadata and (not table_exists or force):
data = get_example_data("san_francisco.csv.gz", make_bytes=True)
pdf = pd.read_csv(data, encoding="utf-8")
pdf = pd.read_csv(data, encoding="utf-8", engine="pyarrow")
start = datetime.datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0
)
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/multiformat_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def load_multiformat_time_series( # pylint: disable=too-many-locals
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
data = get_example_data("multiformat_time_series.json.gz")
data = get_example_data("multiformat_time_series.json.gz", make_bytes=True)
pdf = pd.read_json(data)
# TODO(bkyryliuk): move load examples data into the pytest fixture
if database.backend == "presto":
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/paris.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load_paris_iris_geojson(only_metadata: bool = False, force: bool = False) ->
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
data = get_example_data("paris_iris.json.gz")
data = get_example_data("paris_iris.json.gz", make_bytes=True)
df = pd.read_json(data)
df["features"] = df.features.map(json.dumps)

Expand Down
2 changes: 1 addition & 1 deletion superset/examples/random_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def load_random_time_series_data(
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
data = get_example_data("random_time_series.json.gz")
data = get_example_data("random_time_series.json.gz", make_bytes=True)
pdf = pd.read_json(data)
if database.backend == "presto":
pdf.ds = pd.to_datetime(pdf.ds, unit="s")
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/sf_population_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def load_sf_population_polygons(
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
data = get_example_data("sf_population.json.gz")
data = get_example_data("sf_population.json.gz", make_bytes=True)
df = pd.read_json(data)
df["contour"] = df.contour.map(json.dumps)

Expand Down
2 changes: 1 addition & 1 deletion superset/examples/world_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_world_bank_health_n_pop( # pylint: disable=too-many-locals, too-many-s
table_exists = database.has_table_by_name(tbl_name)

if not only_metadata and (not table_exists or force):
data = get_example_data("countries.json.gz")
data = get_example_data("countries.json.gz", make_bytes=True)
pdf = pd.read_json(data)
pdf.columns = [col.replace(".", "_") for col in pdf.columns]
if database.backend == "presto":
Expand Down
3 changes: 3 additions & 0 deletions superset/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def __init__( # pylint: disable=too-many-locals
except Exception as ex: # pylint: disable=broad-except
logger.exception(ex)

if not pa_data:
column_names = []

self.table = pa.Table.from_arrays(pa_data, names=column_names)
self._type_dict: Dict[str, Any] = {}
try:
Expand Down
1 change: 1 addition & 0 deletions superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def form_post(self, form: CsvToDatabaseForm) -> Response:
try:
df = pd.concat(
pd.read_csv(
engine="pyarrow",
chunksize=1000,
encoding="utf-8",
filepath_or_buffer=form.csv_file.data,
Expand Down
4 changes: 2 additions & 2 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,14 +2172,14 @@ def get_data(self, df: pd.DataFrame) -> VizData:
if df is not None and not df.empty:
if metric:
df = df.sort_values(
utils.get_metric_name(metric), ascending=flt.get("asc")
utils.get_metric_name(metric), ascending=flt.get("asc", False)
)
data[col] = [
{"id": row[0], "text": row[0], "metric": row[1]}
for row in df.itertuples(index=False)
]
else:
df = df.sort_values(col, ascending=flt.get("asc"))
df = df.sort_values(col, ascending=flt.get("asc", False))
data[col] = [
{"id": row[0], "text": row[0]}
for row in df.itertuples(index=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/utils/csv_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_df_to_escaped_csv():
]
csv_str = "\n".join([",".join(row) for row in csv_rows])

df = pd.read_csv(io.StringIO(csv_str))
df = pd.read_csv(io.StringIO(csv_str), engine="pyarrow")

escaped_csv_str = csv.df_to_escaped_csv(df, encoding="utf8", index=False)
escaped_csv_rows = [row.split(",") for row in escaped_csv_str.strip().split("\n")]
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/pandas_postprocessing/test_contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_contribution():
rename_columns=["pct_a"],
)
assert processed_df.columns.tolist() == ["a", "b", "c", "pct_a"]
assert_array_equal(processed_df["a"].tolist(), [1, 3, nan])
assert_array_equal(processed_df["b"].tolist(), [1, 9, nan])
assert_array_equal(processed_df["c"].tolist(), [nan, nan, nan])
assert_array_equal(processed_df["a"].tolist(), [1, 3, 0])
assert_array_equal(processed_df["b"].tolist(), [1, 9, 0])
assert_array_equal(processed_df["c"].tolist(), [0, 0, 0])
EugeneTorap marked this conversation as resolved.
Show resolved Hide resolved
assert processed_df["pct_a"].tolist() == [0.25, 0.75, 0]