Standard treatments of the Buckingham Pi Theorem seem to imply that given a dimensionless function $f$ of variables $q_1, q_2, \dots, q_n$ with associated dimension matrix having rank $r$, there exists a function $\phi$ of $\nu = n-r$ variables and pi groups $\pi_1, \pi_2, \dots, \pi_\nu$ such that $$ f(q_1, q_2, \dots, q_n) = \phi(\pi_1, \pi_2, \dots, \pi_\nu). \tag{$\star$} $$ A pi group is a function of the $q_i$ that takes the form $q_1^{a_1}q_2^{a_2}\cdots q_n^{a_n}$ for some rational $a_1, a_2, \dots, a_n$. If all the $a_i$ are zero, I'll call the pi group "trivial."
A simple counterexample
Consider the case $n=1$ with $q_1 = q$ for notational simplicity, and let the function $f:\mathbb R\to \mathbb R$ be defined by $$ f(q) = \mathrm{sgn}(q) $$ where $\mathrm{sgn}$ is the sign function. This function has the property that $$ f(\lambda q) = f(q) $$ for all positive $\lambda$ -- it's scale-invariant under positive changes of scale, so no matter what dimensions one assigns to $q$, this function is dimensionless, but it cannot be written as a function of pi groups. Indeed if $q$ is dimensionful, then there will be no non-trivial pi groups to speak of, and $\mathrm{sgn}(q)$ is not a pi group.
A less reductive/contrived but essentially equivalent counterexample
Consider the formula for quadratic drag in one dimension: $$ F_d(\rho, A, v) = -\frac{1}{2}C_d\rho A v|v| = -\frac{1}{2}C_d\rho A v^2\mathrm{sgn}(v). $$ Dividing both sides by $\rho A v^2$ reveals a dimensionless quantity $$ f(\rho, A, v) = \frac{F_d(\rho,A, v)}{\rho A v^2} = -\frac{1}{2}C_d\mathrm{sgn}(v) $$ which cannot be written in terms of pi groups. There are no non-trivial pi groups that can be formed from density, area, and velocity, and $\mathrm{sgn}(v)$ is not a pi group.
Error in proof?
In addition to these counterexamples, as I was reading a proof of the Pi Theorem in Bluman and Kumei's Symmetries and Differential Equations, I came across a step in the proof (the statement "Consequently $F$ is independent of $X_n$" right after eq. 1.23) that I believe is erroneous given that we only allow for positive scale transformations when changing units, and I think this error corresponds to missing the possibility of needing both pi groups and sign functions of variables in writing dimensionless quantities in terms of other dimensionless quantities. The crux of the problem with the argument seems to me the assertion that if a function is positive scale invariant, namely $f(\lambda q) = f(q)$ for all positive $\lambda$, then it is constant. The sign function is a counterexample to this assertion. I think the most that can be said about a function $f:\mathbb R\to\mathbb R$ that is positive scale invariant is that it's constant for all negative values and constant for all positive values for potentially different constants.
My question in a nutshell
If a dimensionless quantity $f$ is a function of non-negative quantities $q_1, q_2, \dots, q_n$, then it seems the standard statement of the theorem is correct -- e.g. the proof in Bluman and Kumei goes through without error as far as I can tell, but if one or more variables is allowed to be negative, shouldn't equation ($\star$) above instead be written as $$ f(q_1, q_2, \dots, q_n) = \phi(\mathrm{sgn}(q_1), \mathrm{sgn}(q_2), \dots, \mathrm{sgn}(q_n), \pi_1, \pi_2, \dots, \pi_\nu)? \tag{$\star\star$} $$ I believe that Bluman and Kumei's proof can be modified to prove this slightly weaker version of the theorem.