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

Testing: Add makeTimeDataFrame and makeMixedDataFrame to pueblo.testing.pandas #59

Merged
merged 6 commits into from
Jan 29, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/ngr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ on:
- '.github/workflows/ngr.yml'
- 'pueblo/ngr/**'
- 'tests/ngr/**'
- 'pyproject.toml'
push:
branches: [ main ]
paths:
- '.github/workflows/ngr.yml'
- 'pueblo/ngr/**'
- 'tests/ngr/**'
- 'pyproject.toml'

# Allow job to be triggered manually.
workflow_dispatch:
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changes for pueblo

## Unreleased
- Testing: Add `pueblo.testing.pandas.{makeTimeDataFrame,makeMixedDataFrame}`.
They have been removed from `pandas._testing` on behalf of pandas 2.2.0.

## 2024-01-19 v0.0.6
- Packaging: Fix `MANIFEST.in`
Expand Down
3 changes: 2 additions & 1 deletion pueblo/testing/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from inspect import signature

import pandas as pd
from pandas._testing import makeMixedDataFrame, makeTimeDataFrame
from pandas.io.formats.info import DataFrameInfo

from pueblo.testing.pandas import makeMixedDataFrame, makeTimeDataFrame

logger = logging.getLogger(__name__)


Expand Down
39 changes: 39 additions & 0 deletions pueblo/testing/pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import typing as t

import numpy as np
import pandas as pd


def makeTimeDataFrame(nper=None, freq="B") -> pd.DataFrame:
"""
pandas 2.2.0 removed `pandas._testing.makeTimeDataFrame`.

TST/CLN: Remove makeTime methods
https://github.com/pandas-dev/pandas/pull/56264

:param nper:
:param freq:
:return:
"""
return pd.DataFrame(
np.random.default_rng(2).standard_normal((nper, 4)),
columns=pd.Index(list("ABCD"), dtype=object),
index=pd.date_range("2000-01-01", periods=nper, freq=freq),
)


def getMixedTypeDict() -> t.Tuple[pd.Index, t.Dict[str, t.Any]]:
index = pd.Index(["a", "b", "c", "d", "e"])

data = {
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
"D": pd.bdate_range("1/1/2009", periods=5),
}

return index, data


def makeMixedDataFrame() -> pd.DataFrame:
return pd.DataFrame(getMixedTypeDict()[1])
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dataframe = [
"dask",
"numpy",
"pandas",
"pyarrow",
]
develop = [
"black[jupyter]<24",
Expand Down Expand Up @@ -258,7 +259,7 @@ format = [
# Configure Ruff not to auto-fix (remove!):
# Ignore unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
{ cmd = "ruff --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
{ cmd = "pyproject-fmt pyproject.toml" },
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },
]

lint = [
Expand Down
Loading