10000 Switch dataframe constructor to use dispatch by saulshanabrook · Pull Request #32844 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Switch dataframe constructor to use dispatch #32844

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

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Add test for custom constructor
  • Loading branch information
saulshanabrook committed Mar 20, 2020
commit edd85c3ccbb5e965ef3a55c17e1efb25a441443a
21 changes: 21 additions & 0 deletions pandas/tests/generic/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pandas as pd
from pandas import DataFrame, MultiIndex, Series, date_range
import pandas._testing as tm
from pandas.core.internals.construction import create_dataframe

from .test_generic import Generic

Expand Down Expand Up @@ -169,6 +170,7 @@ def test_set_attribute(self):
df = DataFrame({"x": [1, 2, 3]})

df.y = 2

df["y"] = [2, 4, 6]
df.y = 5

Expand All @@ -183,6 +185,25 @@ def test_deepcopy_empty(self):

self._compare(empty_frame_copy, empty_frame)

def test_register_constructor(self):
# Verify that if you register a custom `create_dataframe` imeplementation
# this will be used in the constructor
class MyCustomObject:
pass

o = MyCustomObject()

with pytest.raises(ValueError):
DataFrame(o)

@create_dataframe.register
def _create_dataframe_custom(o: MyCustomObject, *args, **kwargs):
return create_dataframe(None, *args, **kwargs)

result = DataFrame(o)
expected = DataFrame(None)
self._compare(result, expected)


# formerly in Generic but only test DataFrame
class TestDataFrame2:
Expand Down
0