Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tesi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marco Aceti
Tesi
Commits
588cf8e7
Verified
Commit
588cf8e7
authored
May 4, 2023
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Parallelize dataset loading
parent
b790d25e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/analysis/main.py
+13
-8
13 additions, 8 deletions
src/analysis/main.py
with
13 additions
and
8 deletions
src/analysis/main.py
+
13
−
8
View file @
588cf8e7
...
...
@@ -6,8 +6,8 @@ from datetime import datetime
import
pandas
as
pd
from
dateparser
import
parse
from
joblib
import
Parallel
,
delayed
from
pandas.core.groupby.generic
import
DataFrameGroupBy
from
tqdm
import
tqdm
from
src.analysis
import
groupby
,
stat
,
trajectories_map
from
src.analysis.filter
import
date_filter
,
railway_company_filter
...
...
@@ -71,6 +71,14 @@ def register_args(parser: argparse.ArgumentParser):
)
@delayed
def
_load_train_dataset
(
train_csv
:
str
)
->
pd
.
DataFrame
:
path
=
pathlib
.
Path
(
train_csv
)
train_df
:
pd
.
DataFrame
=
read_train_csv
(
pathlib
.
Path
(
train_csv
))
logging
.
debug
(
f
"
Loaded
{
len
(
train_df
)
}
data points @
{
path
}
"
)
return
train_df
def
main
(
args
:
argparse
.
Namespace
):
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
"
ignore
"
)
...
...
@@ -88,15 +96,12 @@ def main(args: argparse.Namespace):
# Load dataset
df
:
pd
.
DataFrame
|
DataFrameGroupBy
=
pd
.
DataFrame
()
logging
.
info
(
"
Loading datasets...
"
)
for
train_csv
in
(
tqdm
(
args
.
trains_csv
)
if
logging
.
root
.
getEffectiveLevel
()
>
logging
.
DEBUG
else
args
.
trains_csv
for
train_df
in
Parallel
(
n_jobs
=-
1
,
verbose
=
5
)(
_load_train_dataset
(
train_csv
)
for
train_csv
in
args
.
trains_csv
# type: ignore
):
path
=
pathlib
.
Path
(
train_csv
)
train_df
:
pd
.
DataFrame
=
read_train_csv
(
pathlib
.
Path
(
train_csv
))
df
=
pd
.
concat
([
df
,
train_df
],
axis
=
0
)
logging
.
debug
(
f
"
Loaded
{
len
(
train_df
)
}
data points @
{
path
}
"
)
df
.
reset_index
(
drop
=
True
,
inplace
=
True
)
stations
:
pd
.
DataFrame
=
read_station_csv
(
args
.
station_csv
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment