Skip to content

Commit

Permalink
use pandas NA
Browse files Browse the repository at this point in the history
  • Loading branch information
dougbrn committed Apr 16, 2024
1 parent 1818c57 commit 82aac66
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 111 deletions.
5 changes: 2 additions & 3 deletions src/nested_pandas/series/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pandas.core.arrays import ExtensionArray
from pandas.core.dtypes.base import ExtensionDtype

from nested_pandas.series.na import NA, NAType
from nested_pandas.series.utils import is_pa_type_a_list

__all__ = ["NestedDtype"]
Expand All @@ -29,9 +28,9 @@ class NestedDtype(ExtensionDtype):
"""Attributes to use as metadata for __eq__ and __hash__"""

@property
def na_value(self) -> NAType:
def na_value(self) -> pd.NA:
"""The missing value for this dtype"""
return NA
return pd.NA

type = pd.DataFrame
"""The type of the array's elements, always pd.DataFrame"""
Expand Down
10 changes: 9 additions & 1 deletion src/nested_pandas/series/ext_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,16 @@ def to_numpy(self, dtype: None = None, copy: bool = False, na_value: Any = no_de

# Hack with np.empty is the only way to force numpy to create 1-d array of objects
result = np.empty(shape=array.shape, dtype=object)

# TODO: delete block once confirmed NA is better to return
# fill NaNs - Fill with an empty dictionary using the same columns
# nan_vals = pd.isna(array)
# if sum(nan_vals) > 0:
# na_idx = np.where(nan_vals)
# array[na_idx] = {key: [] for key in array[np.where(~nan_vals)[0][0]].keys()}

# We do copy=False here because user's 'copy' is already handled by ArrowExtensionArray.to_numpy
result[:] = [pd.DataFrame(value, copy=False) for value in array]
result[:] = [pd.DataFrame(value, copy=False) if not pd.isna(value) else pd.NA for value in array]
return result

def __setitem__(self, key, value) -> None:
Expand Down
55 changes: 0 additions & 55 deletions src/nested_pandas/series/na.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/nested_pandas/series/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from nested_pandas.series.dtype import NestedDtype
from nested_pandas.series.ext_array import NestedExtensionArray
from nested_pandas.series.na import NA


@pytest.mark.parametrize(
Expand Down Expand Up @@ -62,7 +61,7 @@ def test_from_fields():
def test_na_value():
"""Test that NestedDtype.na_value is a singleton instance of NAType."""
dtype = NestedDtype(pa.struct([pa.field("a", pa.list_(pa.int64()))]))
assert dtype.na_value is NA
assert dtype.na_value is pd.NA


def test_fields():
Expand Down
50 changes: 0 additions & 50 deletions tests/nested_pandas/series/test_na.py

This file was deleted.

0 comments on commit 82aac66

Please sign in to comment.