Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Aug 2, 2023
1 parent 2273459 commit 99f2568
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions dataframe_api_compat/pandas_standard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ def column_from_sequence(
return PandasColumn(ser, name=name)


def column_from_1d_array(
array, *, dtype: Any, name: str | None = None
) -> PandasColumn[Any]: # pragma: no cover
ser = pd.Series(array, dtype=map_standard_dtype_to_pandas_dtype(dtype), name=name)
return PandasColumn(ser)


def dataframe_from_2d_array(
array, *, names: Sequence[str], dtypes: dict[str, Any]
) -> PandasColumn[Any]: # pragma: no cover
df = pd.DataFrame(array, columns=names).astype(
{key: map_standard_dtype_to_pandas_dtype(value) for key, value in dtypes.items()}
)
return PandasDataFrame(df)


def dataframe_from_dict(data: dict[str, PandasColumn[Any]]) -> PandasDataFrame:
for col_name, col in data.items():
if not isinstance(col, PandasColumn): # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion dataframe_api_compat/pandas_standard/pandas_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self._series = column
else:
self._series = column.reset_index(drop=True)
self._name = name
self._name = name # or column.name

def _validate_index(self, index: pd.Index) -> None:
pd.testing.assert_index_equal(self.column.index, index)
Expand Down
2 changes: 1 addition & 1 deletion dataframe_api_compat/polars_standard/polars_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _is_integer_dtype(dtype: Any) -> bool:
class PolarsColumn(Column[DType]):
def __init__(self, column: pl.Series, *, name: str | None = None) -> None:
self._series = column
self._name = name
self._name = name # or column.name

# In the standard
def __column_namespace__(self, *, api_version: str | None = None) -> Any:
Expand Down

0 comments on commit 99f2568

Please sign in to comment.