Skip to content
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

Add DataFrame.size and Series.size #233

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/reference/supported_apis.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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