Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Aug 24, 2024
1 parent a8fde13 commit 2acdc3c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### `0.2.5`

- Fix bug where `exog` and `group_by` did not handle `str` inputs e.g. `exog="x"`.
- Fix bug where `group_by` for `method='fwl'` with exactly 1 exog variable did not work. (Explanation: `method='fwl'` dispatches to a different macro for the special case of 1 exog variable, and `group_by` was not implemented correctly here.)
- Fix bug where `safe` mode did not work for `method='chol'`

### `0.2.4`

- Fix minor incompatibility with Redshift; contributed by [@steelcd](https://github.com/steelcd).
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "dbt_linreg"
version: "0.2.4"
version: "0.2.5"

# 1.2 is required because of modules.itertools.
require-dbt-version: [">=1.2.0", "<2.0.0"]
Expand Down
4 changes: 4 additions & 0 deletions macros/linear_regression/ols.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{% else %}
{% set exog = [exog] %}
{% endif %}
{% elif exog is string %}
{% set exog = [exog] %}
{% endif %}

{% if group_by is not iterable %}
Expand All @@ -68,6 +70,8 @@
{% else %}
{% set group_by = [group_by] %}
{% endif %}
{% elif group_by is string %}
{% set group_by = [group_by] %}
{% endif %}

{% if alpha is not iterable and alpha is not none %}
Expand Down
10 changes: 5 additions & 5 deletions macros/linear_regression/ols_impl_chol/_ols_impl_chol.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
{{ return(d) }}
{% endmacro %}
{% macro _forward_substitution(li) %}
{% macro _forward_substitution(li, safe=true) %}
{% set d = {} %}
{% for i, j in modules.itertools.combinations_with_replacement(li, 2) %}
{% set ns = namespace() %}
Expand All @@ -86,7 +86,7 @@
{% endfor %}
{% set ns.numerator = ns.numerator~')' %}
{% endif %}
{% if adapter.type() == "postgres" %}
{% if safe %}
{% do d.update({(i, j): '('~ns.numerator~'/nullif(i'~j~'j'~j~', 0))'}) %}
{% else %}
{% do d.update({(i, j): '('~ns.numerator~'/i'~j~'j'~j~')'}) %}
Expand Down Expand Up @@ -118,7 +118,7 @@
)) }}
{%- endif %}
{%- set subquery_optimization = method_options.get('subquery_optimization', True) %}
{%- set safe_sqrt = method_options.get('safe', True) %}
{%- set safe_mode = method_options.get('safe', True) %}
{%- set calculate_standard_error = format_options.get('calculate_standard_error', (not alpha)) and format == 'long' %}
{%- if alpha and calculate_standard_error %}
{% do log(
Expand Down Expand Up @@ -171,7 +171,7 @@ _dbt_linreg_xtx as (
),
_dbt_linreg_chol as (
{%- set d = dbt_linreg._cholesky_decomposition(li=xcols, subquery_optimization=subquery_optimization, safe=safe_sqrt) %}
{%- set d = dbt_linreg._cholesky_decomposition(li=xcols, subquery_optimization=subquery_optimization, safe=safe_mode) %}
{%- if subquery_optimization %}
{%- for i in (xcols | reverse) %}
select
Expand Down Expand Up @@ -202,7 +202,7 @@ _dbt_linreg_chol as (
),
_dbt_linreg_inverse_chol as (
{#- The optimal way to calculate is to do each diagonal at a time. #}
{%- set d = dbt_linreg._forward_substitution(li=xcols) %}
{%- set d = dbt_linreg._forward_substitution(li=xcols, safe=safe_mode) %}
{%- if subquery_optimization %}
{%- for gap in (range(0, upto) | reverse) %}
select *,
Expand Down
2 changes: 1 addition & 1 deletion macros/linear_regression/ols_impl_special/_ols_1var.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _dbt_linreg_cmeans as (
{%- endif %}
_dbt_linreg_base as (
select
{{ dbt_linreg._gb_cols(group_by, trailing_comma=True) | indent(4) }}
{{ dbt_linreg._alias_gb_cols(group_by) | indent(4) }}
{%- if alpha and add_constant %}
b.{{ endog }} - _dbt_linreg_cmeans.y as y,
b.{{ exog[0] }} - _dbt_linreg_cmeans.x1 as x1,
Expand Down

0 comments on commit 2acdc3c

Please sign in to comment.