pm4py / pm4py-core

Public repository for the PM4Py (Process Mining for Python) project.
https://pm4py.fit.fraunhofer.de
GNU General Public License v3.0
722 stars 286 forks source link

Error filtering on timeframe #335

Closed rsalas90 closed 2 years ago

rsalas90 commented 2 years ago

When trying to filter on timeframe I receive the following error:

filtered_log = timestamp_filter.filter_traces_contained(log, "2011-01-06 15:06:00", "2022-06-30 17:56:31")

TypeError: replace() takes no keyword arguments filter traces pm4py

fit-alessandro-berti commented 2 years ago

Dear rsalas, try to verify the type of the variable log (print(type(log))).

I can ensure that examples like the following are working well in the current release:

import pm4py

log = pm4py.read_xes("tests/input_data/receipt.xes") print(type(log))

from pm4py.algo.filtering.log.timestamp import timestamp_filter filtered_log = timestamp_filter.filter_traces_contained(log, "2011-03-09 00:00:00", "2012-01-18 23:59:59")

rsalas90 commented 2 years ago

As you can see, the type is an eventlog object eventlog

rsalas90 commented 2 years ago

In the same way, if I want to see the frequency along with the Petrinet after applying alpha miner algorithm I receive the following error. What could be happening? image

fit-alessandro-berti commented 2 years ago

Ok it's not the typing.

I think that the problem is that the type of the timestamp variable in your events (time:timestamp) is string. This can be corrected as in the following example using the module dateutil:

import pm4py import pandas as pd dataframe = pd.read_csv("C:/receipt.csv") log = pm4py.convert_to_event_log(dataframe) from dateutil.parser import parse for trace in log: ... for event in trace: ... event["time:timestamp"] = parse(event["time:timestamp"])

rsalas90 commented 2 years ago

Thank you! That's was the problem, now it's working properly! I had to modify previously the type of the timestamp:

pd.todatetime(df.TIMESTAMP).dt.tz_localize('UTC')

fit-alessandro-berti commented 2 years ago

You're welcome!