Skip to content

Commit

Permalink
TST: compatible with pandas 2.0 (mie-lab#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyeehh committed Apr 18, 2023
1 parent bbc8331 commit d54e74c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions examples/trackintel_basic_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@
"outputs": [],
"source": [
"# we concate sp and tpls to get the whole mobility trace\n",
"trace = sp.append(tpls)\n",
"trace = pd.concat([sp, tpls])\n",
"\n",
"# calculate the overall tracking coverage\n",
"ti.analysis.tracking_quality.temporal_tracking_quality(trace, granularity='all')"
]
Expand Down Expand Up @@ -332,7 +333,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.10.9"
},
"vscode": {
"interpreter": {
Expand Down
2 changes: 0 additions & 2 deletions tests/preprocessing/test_triplegs.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def test_generate_trips_gap_detection(self):
sep=";",
index_col="id",
parse_dates=[0, 1],
infer_datetime_format=True,
dayfirst=True,
)
sp_in["geom"] = Point(1, 1)
Expand All @@ -238,7 +237,6 @@ def test_generate_trips_gap_detection(self):
sep=";",
index_col="id",
parse_dates=[0, 1],
infer_datetime_format=True,
dayfirst=True,
)
tpls_in["geom"] = LineString([[1, 1], [2, 2]])
Expand Down
6 changes: 3 additions & 3 deletions tests/preprocessing/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ def test_list_column(self):
agg_df = pd.DataFrame(agg)
returned_df = _explode_agg("id", "c", orig_df, agg_df)
solution_df = pd.DataFrame(orig)

assert_frame_equal(returned_df, solution_df)

def test_index_dtype_with_None(self):
"""Test if dtype of index isn't changed with None values."""
orig = [
{"a": 1, "c": 0},
]
orig = [{"a": 1, "c": 0}]
agg = [{"id": [0, 1], "c": 0}, {"id": [], "c": 1}]
orig_df = pd.DataFrame(orig, columns=["a"])
agg_df = pd.DataFrame(agg)
returned_df = _explode_agg("id", "c", orig_df, agg_df)
solution_df = pd.DataFrame(orig)

assert_frame_equal(returned_df, solution_df)


Expand Down
6 changes: 5 additions & 1 deletion trackintel/preprocessing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ def _explode_agg(column, agg, orig_df, agg_df):
temp = agg_df.explode(column)
temp = temp[temp[column].notna()]
temp.index = temp[column]
return orig_df.join(temp[agg], how="left")

return_df = orig_df.join(temp[agg], how="left")
# ensure index dtype the same as input
return_df.index = return_df.index.astype(orig_df.index.dtype)
return return_df


def angle_centroid_multipoints(geometry):
Expand Down

0 comments on commit d54e74c

Please sign in to comment.