Skip to content

Commit

Permalink
Merge pull request #1238 from CartoDB/alasarr/cdf-fix-subclassing-1236
Browse files Browse the repository at this point in the history
Fixing sublcassing issues
  • Loading branch information
oleurud committed Nov 25, 2019
2 parents 5f6487e + b4add47 commit 6f4ca6c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cartoframes/core/cartodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def from_file(cls, filename, **kwargs):
gdf = GeoDataFrame.from_file(filename, **kwargs)
return cls(gdf)

@property
def _constructor(self):
return CartoDataFrame

@classmethod
def from_features(cls, features, **kwargs):
gdf = GeoDataFrame.from_features(features, **kwargs)
Expand Down
Empty file added tests/unit/core/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/unit/core/test_cartodataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Unit tests for cartoframes.data."""

import geopandas as gpd
from cartoframes import CartoDataFrame
from shapely.geometry import box

# DATA FRAME SRC BBOX
pol_1 = box(1, 1, 2, 2)
pol_2 = box(3, 3, 4, 4)
GDF_BOX = gpd.GeoDataFrame({'id': [1, 2], 'geometry': [pol_1, pol_2]}, columns=['id', 'geometry'])


class TestCartoDataFrame(object):

def test_basic_inheritance(self, mocker):
"""Test basic inheritance"""
cdf = CartoDataFrame(GDF_BOX)
assert isinstance(cdf, CartoDataFrame)

def test_crs_inhericante(self, mocker):
"""Test basic inheritance"""
cdf = CartoDataFrame(GDF_BOX)
cdf.crs = 'epsg:4326'
cdf = cdf.to_crs('epsg:3857')
assert isinstance(cdf, CartoDataFrame)
assert cdf.crs == 'epsg:3857'

0 comments on commit 6f4ca6c

Please sign in to comment.