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

Move from TravelTimeMatrixComputer etc. classes to TravelTimeMatrix inheriting from pandas.DataFrame/geopandas.GeoDataFrame #337

Open
wklumpen opened this issue Aug 15, 2023 · 12 comments
Labels
enhancement New feature or request

Comments

@wklumpen
Copy link
Contributor

We have the code as written in the documentation, so let's perhaps make a helper function that does as follows:

travel_details["transport_mode"] = travel_details.transport_mode.astype(str)
travel_details["travel time (min)"] = travel_details.travel_time.apply(
    lambda t: round(t.total_seconds() / 60.0, 2)
)
travel_details["wait time (min)"] = travel_details.wait_time.apply(
    lambda t: round(t.total_seconds() / 60.0, 2)
)

# keep all columns except travel time and wait time (which we renamed to
# reflect the unit of measurement)
travel_details = travel_details[
    [
        "from_id",
        "to_id",
        "option",
        "segment",
        "transport_mode",
        "departure_time",
        "distance",
        "travel time (min)",
        "wait time (min)",
        "route",
        "geometry",
    ]
]

Something like r5py.utils.details_to_text(df) or even passing an argument.

@wklumpen wklumpen added the enhancement New feature or request label Aug 15, 2023
@wklumpen wklumpen added this to the More in the future milestone Aug 15, 2023
@christophfink
Copy link
Member

Hm, not sure - it's simple code that people can vopy-and-paste almost verbatim, but it would require more diligence and probably maintenance if we add this to our code.

On a similar note: I thought whether it would be smart to replace the '...Computer' classes with just 'TravelTimeMatrix', 'DetailedItineraries', and make them inherit from pandas.DataFrame/geopandas.GeoDataFrame, i.e., emphasise the output rather than the tool. Then we could also add all kind of (transparent) __-functions for typecasting and arithmetic operations (including child-class wrappesr of to_file() and explore() that handle the column type conversion before calling it's parent

(That would be very pythonic, but a breaking change - which we could introduce now still, but which will be difficult later on. Of course we should add a thin wrapper named like the old 'Computer' class that raises a DeprecationWarning)

@christophfink
Copy link
Member

Sorry for the typos, writing on my phone

@wklumpen
Copy link
Contributor Author

I actually really like the idea of simplifying the names and for using inheritance; would it be a significant (potentially worth it) departure from r5r?

@christophfink
Copy link
Member

I actually really like the idea of simplifying the names and for using inheritance; would it be a significant (potentially worth it) departure from r5r?

I wouldn't think so - R is function-oriented, while Python is an object-oriented language. This difference is reflected in the current differences, already, the change would not be significant, really

@wklumpen
Copy link
Contributor Author

I'm all for it. Do we need a 3rd? @HTenkanen?

@christophfink christophfink changed the title Add helper function to convert detailed itineraries output to CSV-format Move from TravelTimeMatrixComputer etc. classes to TravelTimeMatrix inheriting from pandas.DataFrame/geopandas.GeoDataFrame Aug 24, 2023
@wklumpen
Copy link
Contributor Author

Since this is a breaking namespace change I suggest this should probably be a target for v0.2 since this technically falls under a MAJOR change according to semantic versioning, but we don't have a MAJOR increment yet until we're at 1.0

@christophfink
Copy link
Member

Absolutely. We should do this soon, though, precisely because it is a breaking change (even though I’d propose wrappers that raise a DeprecationWarning but work as previously). Should we increase the version number of the ‘paper’ release then, to 0.2.0

@wklumpen
Copy link
Contributor Author

Am in favour of this change

@HTenkanen
Copy link
Contributor

I'm also supporting this change to shorter names 👍🏻

@wklumpen
Copy link
Contributor Author

For consideration, an alternative way to extend without inheritance:

https://pandas.pydata.org/docs/development/extending.html

@christophfink
Copy link
Member

For consideration, an alternative way to extend without inheritance:

https://pandas.pydata.org/docs/development/extending.html

This looks enticing! Have to take a closer look :)

@wklumpen
Copy link
Contributor Author

wklumpen commented Sep 1, 2023

Having played around with it now I'm not sure it fits our model - it just adds separate methods to the namespace under a sub-space

GeoPandas just extends the actual class which you can do with some additional namespace stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants