BUG: 'GeometryArray' object has no attribute 'value_counts'
See original GitHub issue-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of geopandas.
-
(optional) I have confirmed this bug exists on the master branch of geopandas.
Code Sample, a copy-pastable example
gdf["geometry"].value_counts()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-fb6329993e01> in <module>
----> 1 gdf["geometry"].value_counts()
C:\tools\miniconda3\envs\project-dev\lib\site-packages\pandas\core\base.py in value_counts(self, normalize, sort, ascending, bins, dropna)
1243 dtype: int64
1244 """
-> 1245 result = value_counts(
1246 self,
1247 sort=sort,
C:\tools\miniconda3\envs\project-dev\lib\site-packages\pandas\core\algorithms.py in value_counts(values, sort, ascending, normalize, bins, dropna)
790
791 # handle Categorical and sparse,
--> 792 result = Series(values)._values.value_counts(dropna=dropna)
793 result.name = name
794 counts = result._values
AttributeError: 'GeometryArray' object has no attribute 'value_counts'
Problem description
The “geometry” columns of a geopandas data frame should act like a regular pandas Series. This includes supporting “value_counts”.
I can’t even monkey-patch it with something that uses collections.Counter
since the geometry types are unhashable, i.e. the following also fails:
import collections
pd.Series(collections.Counter(gdf["geometry"]), name="geometry")
Expected Output
Same as pd.Series.value_counts(*args, **kwargs)
Output of geopandas.show_versions()
SYSTEM INFO
python : 3.8.6 | packaged by conda-forge | (default, Nov 27 2020, 18:58:29) [MSC v.1916 64 bit (AMD64)] executable : C:\tools\miniconda3\envs\project-dev\python.exe machine : Windows-10-10.0.18362-SP0
GEOS, GDAL, PROJ INFO
GEOS : None GEOS lib : None GDAL : 3.1.4 GDAL data dir: None PROJ : 7.1.1 PROJ data dir: C:\tools\miniconda3\envs\project-dev\Library\share\proj
PYTHON DEPENDENCIES
geopandas : 0.8.1 pandas : 1.1.5 fiona : 1.8.18 numpy : 1.19.4 shapely : 1.7.1 rtree : 0.9.4 pyproj : 2.6.1.post1 matplotlib : 3.3.3 mapclassify: 2.3.0 geopy : 2.0.0 psycopg2 : None geoalchemy2: None pyarrow : 2.0.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
I think I’ll work on this as well, seems pretty straightforward and nice to have.
Yes, that would be the idea. Something like this (untested code), method on GeometryArray: