-
Notifications
You must be signed in to change notification settings - Fork 905
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
Include Python object size in .nbytes attribute #2356
base: main
Are you sure you want to change the base?
Conversation
Do you have an idea how often is this called internally? I assume that Dask uses it, in which case having more reasonable estimate might resolve some of our memory issues in dask-geopandas. I am sort of not super happy about this solution as it is better but still way off (unless you have just point geometry), so if we think that the slowdown caused by calling |
I think getting the number of coordinates is generally pretty cheap. For example for the US zip codes:
Although that's a dataset with relatively small number of rows with larger polygons each. With some random data:
The question is maybe how often dask calls this. If it doesn't do this repeatedly, the additional time is probably not a worry. |
Given that this is a strict improvement, although certainly not yet ideal, we can maybe merge this already, and leave counting the coordinates for a future issue/PR? |
Let's give it a go. |
We could actually also add a However, that wouldn't help for dask. But, dask-geopandas could register a function to measure the size of a GeoDataFrame/GeoSeries ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very well across the dask/ dask-geopandas context, but from a pure geopandas/ python perspective, PR looks fine to me
Edit: unless there is also a readme message to add.
To get a slightly better estimate (but still cheap) of the memory usage (the
np.ndarray.nbytes
for an object dtype array only counts the array of pointers, and not the size of objects it is pointing to).The size of the Python geometry object is fixed (for pygeos at least, 32 bytes on Python 3.9), so also does not yet include an estimate of the size of the coordinate sequences.
In principle we could add a
count_coordinates(self.data) * 8
to get a better estimate, but that of course incurs some computation (although a relatively cheap one).