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

MAINT: Repalce row_stack with vstack #202

Merged
merged 2 commits into from
Jan 1, 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
3 changes: 3 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- "*"
pull_request:
branches:
- "*"

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions doc/stateful-transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ just similar enough for you to miss the problem until it's too late.)
{"x": data["x"][2:]}]
dinfo = incr_dbuilder("naive_center(x)", lambda: iter(data_chunked))
# Broken!
np.row_stack([build_design_matrices([dinfo], chunk)[0]
np.vstack([build_design_matrices([dinfo], chunk)[0]
for chunk in data_chunked])

But if we use the proper stateful transform, this just works:
Expand All @@ -111,7 +111,7 @@ But if we use the proper stateful transform, this just works:

dinfo = incr_dbuilder("center(x)", lambda: iter(data_chunked))
# Correct!
np.row_stack([build_design_matrices([dinfo], chunk)[0]
np.vstack([build_design_matrices([dinfo], chunk)[0]
for chunk in data_chunked])

.. note::
Expand Down
4 changes: 2 additions & 2 deletions patsy/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def combine(cls, constraints):
for constraint in constraints:
if constraint.variable_names != variable_names:
raise ValueError("variable names don't match")
coefs = np.row_stack([c.coefs for c in constraints])
constants = np.row_stack([c.constants for c in constraints])
coefs = np.vstack([c.coefs for c in constraints])
constants = np.vstack([c.constants for c in constraints])
return cls(variable_names, coefs, constants)

def test_LinearConstraint():
Expand Down
2 changes: 1 addition & 1 deletion patsy/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def stateful_transform_wrapper(*args, **kwargs):
# self._kwargs = kwargs
#
# def memorize_finish(self):
# all_data = np.row_stack(self._data)
# all_data = np.vstack(self._data)
# args = self._args
# kwargs = self._kwargs
# del self._data
Expand Down
6 changes: 3 additions & 3 deletions patsy/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def check_stateful(cls, accepts_multicolumn, input, output, *args, **kwargs):
elif all_outputs[0].ndim == 1:
all_output1 = np.concatenate(all_outputs)
else:
all_output1 = np.row_stack(all_outputs)
all_output1 = np.vstack(all_outputs)
assert all_output1.shape[0] == len(input)
# output_obj_reshaped = np.asarray(output_obj).reshape(all_output1.shape)
# assert np.allclose(all_output1, output_obj_reshaped)
Expand All @@ -101,11 +101,11 @@ def check_stateful(cls, accepts_multicolumn, input, output, *args, **kwargs):
# handles both Series and DataFrames
all_input = pandas.concat(input_obj)
elif np.asarray(input_obj[0]).ndim == 1:
# Don't use row_stack, because that would turn this into a 1xn
# Don't use vstack, because that would turn this into a 1xn
# matrix:
all_input = np.concatenate(input_obj)
else:
all_input = np.row_stack(input_obj)
all_input = np.vstack(input_obj)
all_output2 = t.transform(all_input, *args, **kwargs)
if have_pandas and isinstance(input_obj[0], pandas_type):
assert np.array_equal(all_output2.index, pandas_index)
Expand Down
Loading