Add DataFrame.size and Series.size

This commit is contained in:
Seth Michael Larson 2020-07-13 17:30:14 -05:00 committed by GitHub
parent d50e06dda5
commit 6c2f9a2ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

View File

@ -338,7 +338,7 @@ script instead of being modified manually.
+---------------------------------------+------------+ +---------------------------------------+------------+
| ``ed.DataFrame.shift()`` | No | | ``ed.DataFrame.shift()`` | No |
+---------------------------------------+------------+ +---------------------------------------+------------+
| ``ed.DataFrame.size`` | No | | ``ed.DataFrame.size`` | **Yes** |
+---------------------------------------+------------+ +---------------------------------------+------------+
| ``ed.DataFrame.skew()`` | No | | ``ed.DataFrame.skew()`` | No |
+---------------------------------------+------------+ +---------------------------------------+------------+
@ -910,7 +910,7 @@ script instead of being modified manually.
+---------------------------------------+------------+ +---------------------------------------+------------+
| ``ed.Series.shift()`` | No | | ``ed.Series.shift()`` | No |
+---------------------------------------+------------+ +---------------------------------------+------------+
| ``ed.Series.size`` | No | | ``ed.Series.size`` | **Yes** |
+---------------------------------------+------------+ +---------------------------------------+------------+
| ``ed.Series.skew()`` | No | | ``ed.Series.skew()`` | No |
+---------------------------------------+------------+ +---------------------------------------+------------+

View File

@ -17,6 +17,7 @@
import sys import sys
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Tuple
from eland.query_compiler import QueryCompiler from eland.query_compiler import QueryCompiler
@ -505,3 +506,28 @@ class NDFrame(ABC):
@abstractmethod @abstractmethod
def sample(self, n=None, frac=None, random_state=None): def sample(self, n=None, frac=None, random_state=None):
pass 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

View File

@ -38,3 +38,10 @@ class TestDataFrameShape(TestData):
ed_shape = ed_flights.shape ed_shape = ed_flights.shape
assert pd_shape == ed_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