Skip to content

Pandas 1.0 compatibility: to_numpy() instead of as_matrix() #3794

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

Merged
merged 1 commit into from
Feb 1, 2020
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
6 changes: 3 additions & 3 deletions pymc3/glm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def any_to_tensor_and_labels(x, labels=None):
if isinstance(x, pd.DataFrame):
if not labels:
labels = x.columns
x = x.as_matrix()
x = x.to_numpy()

# pandas.Series
# there can still be a label
# we can override labels
elif isinstance(x, pd.Series):
if not labels:
labels = [x.name]
x = x.as_matrix()[:, None]
x = x.to_numpy()[:, None]

# dict
# labels are keys,
Expand All @@ -66,7 +66,7 @@ def any_to_tensor_and_labels(x, labels=None):
try:
x = pd.DataFrame.from_dict(x)
labels = x.columns
x = x.as_matrix()
x = x.to_numpy()
# some types fail there
# another approach is to construct
# variable by hand
Expand Down
16 changes: 8 additions & 8 deletions pymc3/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class TestARM12_6(SeededTest):
def build_model(self):
data = get_city_data()

self.obs_means = data.groupby('fips').lradon.mean().as_matrix()
self.obs_means = data.groupby('fips').lradon.mean().to_numpy()

lradon = data.lradon.as_matrix()
floor = data.floor.as_matrix()
group = data.group.as_matrix()
lradon = data.lradon.to_numpy()
floor = data.floor.to_numpy()
group = data.group.to_numpy()

with pm.Model() as model:
groupmean = pm.Normal('groupmean', 0, 10. ** -2.)
Expand Down Expand Up @@ -107,10 +107,10 @@ def build_model(self):
data = get_city_data()
self.obs_means = data.groupby('fips').lradon.mean()

lradon = data.lradon.as_matrix()
floor = data.floor.as_matrix()
group = data.group.as_matrix()
ufull = data.Uppm.as_matrix()
lradon = data.lradon.to_numpy()
floor = data.floor.to_numpy()
group = data.group.to_numpy()
ufull = data.Uppm.to_numpy()

with pm.Model() as model:
groupmean = pm.Normal('groupmean', 0, 10. ** -2.)
Expand Down