Skip to content

Commit

Permalink
Add DataFrame.size and Series.size
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Jul 13, 2020
1 parent d50e06d commit 6c2f9a2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/source/reference/supported_apis.rst
Expand Up @@ -338,7 +338,7 @@ script instead of being modified manually.
+---------------------------------------+------------+
| ``ed.DataFrame.shift()`` | No |
+---------------------------------------+------------+
| ``ed.DataFrame.size`` | No |
| ``ed.DataFrame.size`` | **Yes** |
+---------------------------------------+------------+
| ``ed.DataFrame.skew()`` | No |
+---------------------------------------+------------+
Expand Down Expand Up @@ -910,7 +910,7 @@ script instead of being modified manually.
+---------------------------------------+------------+
| ``ed.Series.shift()`` | No |
+---------------------------------------+------------+
| ``ed.Series.size`` | No |
| ``ed.Series.size`` | **Yes** |
+---------------------------------------+------------+
| ``ed.Series.skew()`` | No |
+---------------------------------------+------------+
Expand Down
26 changes: 26 additions & 0 deletions eland/ndframe.py
Expand Up @@ -17,6 +17,7 @@

import sys
from abc import ABC, abstractmethod
from typing import Tuple

from eland.query_compiler import QueryCompiler

Expand Down Expand Up @@ -505,3 +506,28 @@ def tail(self, n=5):
@abstractmethod
def sample(self, n=None, frac=None, random_state=None):
pass

@property
def shape(self) -> Tuple[int, ...]:
raise NotImplementedError

@property
def size(self) -> int:
"""
Return an int representing the number of elements in this object.
Return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame.
Returns
-------
int:
Number of elements in the object
See Also
--------
:pandas_api_docs:`pandas.DataFrame.size`
"""
product = 0
for dim in self.shape:
product = (product or 1) * dim
return product
7 changes: 7 additions & 0 deletions eland/tests/dataframe/test_shape_pytest.py
Expand Up @@ -38,3 +38,10 @@ def test_flights_shape(self):
ed_shape = ed_flights.shape

assert pd_shape == ed_shape

def test_size(self):
pd_flights = self.pd_flights()
ed_flights = self.ed_flights()

assert pd_flights.size == ed_flights.size
assert pd_flights.FlightDelayMin.size == ed_flights.FlightDelayMin.size

0 comments on commit 6c2f9a2

Please sign in to comment.